Android 2.0 contact groups manipulation

Posted by Bao Le on Stack Overflow See other posts from Stack Overflow or by Bao Le
Published on 2010-06-11T22:52:16Z Indexed on 2010/06/12 8:22 UTC
Read the original article Hit count: 711

Filed under:
|
|

I would manipulate the contact groups in Android 2.O. My code is following:

To get a list of group (with id and title):

final String[] GROUP_PROJECTION = new String[] { ContactsContract.Groups._ID, ContactsContract.Groups.TITLE };
Cursor cursor = ctx.managedQuery(ContactsContract.Groups.CONTENT_URI, GROUP_PROJECTION, null, null, ContactsContract.Groups.TITLE + " ASC");

Later, on an ListView, I select a group (onClick event) and read all contacts belong to this selected group by following code:

    String where = ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID
            + "="
            + groupid
            + " AND "
            + ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE
            + "='"
            + ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE
            + "'";

Problem: ContactsContract.Groups._ID in the first query does not match with the ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID in the second query.

Any solution/suggestion?

Thanks

© Stack Overflow or respective owner

Related posts about android

Related posts about contacts