I want to get all contact in local address book of Android device by Group Name. Such as "Family", "Friends", "Work" ... like Address book in android device.
Here is my code:
public void getAllContactsByGroup(ContentResolver cr) {
String a = "Friends";
Uri CONTENT_URI_GR = ContactsContract.Groups.CONTENT_URI;
String GR_ID = ContactsContract.Groups._ID;
String GR_NAME = ContactsContract.Groups.TITLE;
Cursor cursor = getContentResolver().query(CONTENT_URI_GR,
null, GR_NAME + "=?", new String[] { a }, null);
while (cursor.moveToNext())
{
Uri CONTENT_URI = ContactsContract.Contacts.CONTENT_URI;
String _ID = ContactsContract.Contacts._ID;
String DISPLAY_NAME = ContactsContract.Contacts.DISPLAY_NAME;
Cursor phones = cr.query(CONTENT_URI, null, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
countContact = phones.getCount();
while (phones.moveToNext())
{
contact_id = phones.getString(phones.getColumnIndex(_ID));
String name = phones.getString(phones.getColumnIndex(DISPLAY_NAME));
name1.add(name);
_idd.add(contact_id);
}
phones.close();
}
cursor.close();
}
I tried to get all contact in group "Friends" of Address book, but it gets all contacts of all groups.