1

I get a list of contacts in a given group id by id:

Cursor cur = ctx.managedQuery(ContactsContract.Data.CONTENT_URI,
             new String[] { GroupMembership.GROUP_ROW_ID,
        GroupMembership.CONTACT_ID },
        GroupMembership.GROUP_ROW_ID + "=" + String.valueOf(id),
        null, null);

if (cur.moveToFirst()) {
    int groupIdx = cur.getColumnIndex(GroupMembership.GROUP_ROW_ID);
    int personIdx = cur.getColumnIndex(GroupMembership.CONTACT_ID);

    do {
        if (cur.getLong(groupIdx) == id) {
            Cursor ccur = ctx.getContentResolver().query( Phone.CONTENT_URI,
                new String[] {Phone.NUMBER, Phone.TYPE,
                Phone.DISPLAY_NAME },
                Phone.CONTACT_ID +"="+ contactId, 
                      null, null); 
            Log.e("Test: Number", ccur.getString(0))
            Log.e("Test: Name", ccur.getString(2))
        }
    } while (cur.moveToNext());
}

But it seems that does not work correctly.

ekad
  • 14,436
  • 26
  • 44
  • 46
Bao Le
  • 16,643
  • 9
  • 65
  • 68

1 Answers1

3

Probably you are missing the mimetype.

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

        Cursor c = this.ctx.getContentResolver().query(
                ContactsContract.Data.CONTENT_URI,
                new String[] {
                        ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID,
                        ContactsContract.Data.DISPLAY_NAME
                }, where, null, ContactsContract.Data.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
Pentium10
  • 204,586
  • 122
  • 423
  • 502
  • Thanks for you quick reply. What is the different between ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID and ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID ? – Bao Le Jun 09 '10 at 21:55
  • http://groups.google.com/group/android-developers/browse_thread/thread/77d579d60d803094 – Pentium10 Jun 09 '10 at 21:57