I am trying to add a phone number to an existing contact on a Droid phone. Performing this process at the same time as creating the contact is trivial, because when I create the ContentProviderOperation I provide just 0. But trying to find the backlink using a query 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 get the raw contact ID, the following code simply throws an IndexOutOfBoundException (rawConcactReferenceID is a variable obtained from the previous request):
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 problem is the huge lack of good documentation. I would be very pleased if I just got work on working copies to study.
Greetings
source share