I Finally found a solution for the second problem :

I was creating the contact in severals times (create RawContact and
add all data of contact after)

So yet I'm using this code :

ArrayList<ContentProviderOperation> ops = new
ArrayList<ContentProviderOperation>();
        
ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
 // /
                                
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE,
contact.getAccounts().get(0)[0]) //
                                
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME,
contact.getAccounts().get(0)[1]) //
                                .build());
        
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) //
                                
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,
0) //
                                .withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE) //
                                
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
contact.getDisplayName()) //
                                .build());
                if (contact.getPhone() != null && contact.getPhone().size() > 
0) {
                        for (Phone phone : contact.getPhone()) {
        
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) //
                                                
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,
0) //
                                                
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE) //
                                                
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER,
phone.getNumber()) //
                                                
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE,
phone.getType()) //
                                                
.withValue(ContactsContract.CommonDataKinds.Phone.LABEL,
phone.getLabel()) //
                                                .build());
                        }

                }


And now I have a lookupKey valuated :) !

On 10 mai, 14:08, jef <[email protected]> wrote:
> Hello I'm a newbie with manipulation of Contact API
>
> I would create an application that saved a references to chosen
> contacts and create nex contacts.
>
> So I first think of contact id but i have read that it was a bad idea
> and the lookupkey was here for that ! So I try to play with lookupKey
> and i'm facing some little problems...
>
> First :
>
> I choose a contact to saved, I did it by getting it's lookUpKey : no
> problem.
> I try to access later to contact with it's lookUpKey : no problem.
>
> I go to contact native application, I change the first name of the
> choosen contact.
> I go in my application an try to access to choosen contact with saved
> lookUpKey : problem, the contact lookUpKey has changed because I
> change the first name...
>
> Is there a way to have a unique access to a contact ? Or I was imagine
> to register to modification done on my contact ? How could I solve my
> problem ?
>
> Second :
>
> I created a contact with this  code :
>
> ContentValues values = new ContentValues();
> Uri rawContactUri =
> cr.insert(ContactsContract.RawContacts.CONTENT_URI, values);
> long rawContactId = ContentUris.parseId(rawContactUri);
>
> this.cur = this.cr.query(rawContactUri, new String[]
> { ContactsContract.RawContacts.CONTACT_ID }, null, null, null);
> String id = null;
> if (this.cur.moveToFirst()) {
>         id =
> cur.getString(cur.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID));
>         this.cur = this.cr.query(ContactsContract.Contacts.CONTENT_URI, null,
> ContactsContract.Contacts._ID + " =  ?", new String[] { id }, null);
>         if (this.cur.moveToFirst()) {
>                 Log.i("ContactAPI5", "LookUpCreate : " +
> cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)));
>         } else {
>                 Log.i("ContactAPI5", "no contact created");
>         }
>
> }
>
> And for these code, the result of lookUpKey is always an empty string.
> Why do I have an empty string ?
>
> Best regards
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to