How do I add contact to a group on Android?

℡╲_俬逩灬. 提交于 2019-11-29 08:49:52

I found the resolution and I post it here:

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

}

But I don't get something, why do I have to use RAW_CONTACT_ID and not CONTACT_ID, the later raises nullpointerexception.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!