I am currently working on an app, where I need to insert contacts into the mobilephones contact list. Using the ContactsContract.RawContacts batch insertion, I successfully inserted contacts into the phonebook.
http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html
However when trying to update them they just add more phonenumber, instead replacing the old one.
So I came onto ContactsContract.Data where through the Contact_ID one could apparently on update replace the old phonenumber.
http://developer.android.com/reference/android/provider/ContactsContract.Data.html
My question now is, is it possible to retrieve the Contacts_ID on insertion? So that when I insert a contact by this code:
ArrayList<ContentProviderOperation> ops =
new ArrayList<ContentProviderOperation>();
...
int rawContactInsertIndex = ops.size();
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE, accountType)
.withValue(RawContacts.ACCOUNT_NAME, accountName)
.build());
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME, "Mike Sullivan")
.build());
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
I would get back the Contacts_ID?
Thank you advance for any help you can give me.