1

I want to add a contact to a specific group I am having all the group names and their Id's by using ContactsContract.Groups._ID, now I want to add a contact to a group by this id. i.e insert some contact id to some group id.

I have retrieved both group and Raw contact id's please tell me the query to do this.

ekad
  • 14,436
  • 26
  • 44
  • 46

1 Answers1

0

I have found the answer at How do I add contact to a group on Android? to Pentium10

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

    }
Community
  • 1
  • 1