Im trying to add a phone number to an already existing contact on a Droid-phone. Doing it at the same time as I create a contact is trivial, as the backreference I supply simply is 0 when creating a ContentProviderOperation. But trying to find the backreference through querying for a display name like this does not work:
Cursor rawContactsReferenceCursor =
contentResolver.query(Data.CONTENT_URI,
new String[]{Data.RAW_CONTACT_ID},
Data.DISPLAY_NAME+"=\""+displayName+"\"", null, null);
While I do get a raw contact ID, the following code just generates an IndexOutOfBoundException (rawConcactReferenceID is the variable I got from the previous query):
ArrayList<ContentProviderOperation> op_list =
new ArrayList<ContentProviderOperation>();
op_list.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, rawConcactReferenceID)
.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
.withValue(Phone.NUMBER, testNumber)
.withValue(Phone.TYPE, Phone.TYPE_CUSTOM)
.withValue(Phone.LABEL, testLabel)
.build());
ContentProviderResult[] result =
contentResolver.applyBatch(ContactsContract.AUTHORITY, op_list);
The big challenge is a huge lack of good documentation. I would be very satisfied to just get my hands on some working copypasta to study.
Cheers,