I recently created a Sync adapter for my app, It will sync contacts I am getting via a web request with the contacts in the phone. I have no problem adding the contact, however I cannot get the contact information to correctly update when contact information has changed. For example the Company Name field on the contact. Here is some example queries I have tried that did not work or only partially worked(ie - some contacts updated but not correctly):
ContentValues values = new ContentValues();
values.put(ContactsContract.CommonDataKinds.Organization.COMPANY, "New Company");
context.getContentResolver().update(Uri.parse("content://com.android.contacts/data/"), values, BaseColumns._ID + "=?", new String[] { String.valueOf(id) } );
I have also tried doing this in batch as suggested by the android documentation:
builder = ContentProviderOperation
.newUpdate(ContactsContract.Data.CONTENT_URI);
builder.withSelection(BaseColumns._ID + " =?", new String[]{String.valueOf(id)});
builder.withValue(
ContactsContract.CommonDataKinds.Organization.COMPANY,
"New Company Name!");
operationList.add(builder.build());
I have read the ContactContracts Documentation and originally was following this tutorial. I also checked into the AuthenticatorActivity
example in the api's to no avail. Any help is greatly appreciated.