I'm writing an Android application (Android 2.1). I couldn't figure out how to update a given name or family name of a contact. Below is the code I have. It doesn't work (the program dies when I run it):
ContentProviderOperation.Builder builderName = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI);
selectArgs1 = ContactsContract.Data.CONTACT_ID + "=?" + StructuredName.CONTENT_ITEM_TYPE + " = ?";
selectArg2 = new String[]{id, ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME};
builderName.withSelection(selectArgs1, selectArg2);
builderName.withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, "my test name");
operationList.add(builderName.build());
I tried GIVEN_NAME, NICK_NAME, and DISPLAY_NAME, nonce of the worked. On the other hand, I can update the notes with the following code:
ContentProviderOperation.Builder builderNote = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI);
selectArgs1 = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
selectArg2 = new String[] {id, ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE};
builderNote.withSelection(selectArgs1, selectArg2);
builderNote.withValue(ContactsContract.CommonDataKinds.Note.NOTE, "test note abc");
operationList.add(builderNote.build());
It's been puzzling me for quite a few days.开发者_高级运维 I'm surprised that updating names is so difficult to figure out. Your help is grealy appreciated. Thanks in advance!
精彩评论