1

I read about ContactsContract.CommonDataKinds.GroupMembership, but I can't figure out what URI use to insert to.

I have prepared this method:

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

    }

Can someone tell me what URI to use in SDK 2.0+?

Pentium10
  • 204,586
  • 122
  • 423
  • 502

1 Answers1

6

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.

Pentium10
  • 204,586
  • 122
  • 423
  • 502
  • 3
    It's because a contact_id is a "virtual contact" made up of 1+ raw contacts- For instance, a contact in your facebook account merged with one on your google contact list merged with one in your twitter account... They would all map to the same contact ID, but be seperate raw contacts. – callingshotgun Feb 09 '11 at 17:04