开发者

How to update a given name or family name of a contact in Android

开发者 https://www.devze.com 2023-04-12 18:39 出处:网络
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 ru

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消