如何在Android中更新联系人的给定姓名或姓氏

时间:2011-10-14 05:05:06

标签: android contact android-contacts

我正在编写Android应用程序(Android 2.1)。我无法弄清楚如何更新联系人的给定姓名或姓氏。以下是我的代码。它不起作用(程序在我运行时死亡):

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());

我尝试了GIVEN_NAME,NICK_NAME和DISPLAY_NAME。另一方面,我可以使用以下代码更新注释:

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());

这让我困惑了好几天。我很惊讶更新名称很难弄明白。非常感谢您的帮助。提前谢谢!

0 个答案:

没有答案