我成功更新了联系人中使用的现有NOTE getContentResolver()。applyBatch(ContactsContract.AUTHORITY,ops);
此方法不适用于添加新的NOTE .. 如何在ANDROID中添加现有CONTACT的新NOTE?
答案 0 :(得分:1)
public void testInsert()
{
ContentValues values = new ContentValues();
// insert a empty note into RawContacts.CONTENT_URI, and get the rawContactId
Uri rawContactUri = this.getContext().getContentResolver().insert(RawContacts.CONTENT_URI, values);
// get id
long rawContactId = ContentUris.parseId(rawContactUri);
// insert name data
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId); // id
values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);// MIMETYPE
values.put(StructuredName.GIVEN_NAME, "zetsin");// first name
this.getContext().getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
// insert phone
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(Phone.NUMBER, "123456");
values.put(Phone.TYPE, Phone.TYPE_MOBILE);
this.getContext().getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
// insert email
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
values.put(Email.DATA, "zetsin@gmail.com");
values.put(Email.TYPE, Email.TYPE_WORK);
this.getContext().getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
}