0

I want to get the group id of each contact in my android application.I have initial query like this

Cursor cursor = cr.query(Phone.CONTENT_URI,
                new String[] { 
                Phone.CONTACT_ID}, null, null, null);

And what i do is get details of each which related to this CONTACT_ID.I have manage to get phone number,names,addresses and emails so far but still couldn't manage to get the group id of the contact.

P.S i found a question asked before here but the class android.provider.Contacts.GroupMembership is deprecated.

thanks.

Community
  • 1
  • 1
sampathpremarathna
  • 4,044
  • 5
  • 25
  • 37

1 Answers1

0

Try this:

final String selection = "mimetype_id = (select _id from mimetypes where mimetype = \"" + 
        vnd.android.cursor.item / group_membership + "\")";

Cursor cursor = getContentResolver().query(Data.CONTENT_URI,
        new String[]{Phone.CONTACT_ID}, selection, null, null);
try {
    if (cursor != null && cursor.moveToFirst()) {
        do {
            Log.i("Details", "Contact IDs" + cursor.getLong(cursor.getColumnIndex(Phone.CONTACT_ID)));
        } while (cursor.moveToNext());
    }
} finally {
    if (cursor != null) {
        cursor.close();
    }
}
Alex K
  • 22,315
  • 19
  • 108
  • 236
Ruchit Mittal
  • 312
  • 1
  • 9