Does anybody know how to get a list of contacts belonging to a 1 specific group in Android?
I need something like this:
Select * from contacts where group_id = "1234"
I am able to get a list of all contacts OR all groups by using something like this:
Cursor groupCursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
final ArrayList<String> contacts = new ArrayList<String>();
while(groupCursor.moveToNext()) {
String name = groupCursor.getString(groupCursor.getColumnIndex(ContactsContract.Constacts.DisplayName ));
contacts.add(name);
}
this is what i use and it works fine for me
Uri groupURI = ContactsContract.Data.CONTENT_URI;
String[] projection = new String[]{
ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID ,
ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID};
Cursor c = managedQuery(groupURI,
projection,
ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID+"="+groupID,
null,null);
this requires you to have the Group id already and that can be found by querying ContactsContract.Groups