我读到了 ContactsContract.CommonDataKinds.GroupMembership,但我无法弄清楚要插入的URI.
我准备了这个方法:
public static Uri addToGroup(ContentResolver resolver, long personId, long groupId) { ContentValues values = new ContentValues(); values.put(ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID, personId); values.put(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID, groupId); return resolver.insert(uri, values);//URI is not known }
有人能告诉我在SDK 2.0+中使用什么URI吗?
我找到了决议,我在这里发布:
public Uri addToGroup(long personId, long groupId) { //remove if exists this.removeFromGroup(personId, groupId); ContentValues values = new ContentValues(); values.put(ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID, personId); values.put( ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID, groupId); values .put( ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE, ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE); return this.ctx.getContentResolver().insert( ContactsContract.Data.CONTENT_URI, values); }
但是我没有得到什么,为什么我必须使用RAW_CONTACT_ID
而不是CONTACT_ID
,后来引发了nullpointerexception.