Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It looks strange because ContactsContract.Contacts does not have ContactsContract.Groups.TITLE column. So I think that you can get group id with the group title you want and then search contacts with the group id. The idea might go like following:</p> <pre><code> public String getGroupIdByTitle(String groupTitle){ try { cursor = mContentResolver.query( ContactsContract.Groups.CONTENT_URI, new String[] {Groups._ID}, Groups.TITLE + "=?", new String[]{groupTitle}, null); while (cursor.moveToNext()){ return cursor.getString(cursor.getColumnIndex(0); } } finally { if (cursor!=null) cursor.close(); } return ""; } public String getGroupIdOfContact(String lookupKey) { String where = String.format("%s=? AND %s=?", Data.LOOKUP_KEY, Data.MIMETYPE); String[] whereArgs = {lookupKey, GroupMembership.CONTENT_ITEM_TYPE}; String groupRowId = ""; Cursor cursor = mContentResolver.query( Data.CONTENT_URI, new String[]{GroupMembership.GROUP_ROW_ID}, where, whereArgs, null); try { if (cursor.moveToNext()) { return cursor.getString(cursor.getColumnIndex(GroupMembership.GROUP_ROW_ID)); } } finally { if (cursor!=null) cursor.close(); } return ""; } public void deleteContactByGroupTitle(String groupTitle) { String targetGroupId = getGroupIdByTitle(groupTitle); Cursor cursor = null; try { cursor = mContentResolver.query(Contacts.CONTENT_URI, null, null, null, null); while (cursor.moveToNext()){ String lookupKey = cursor.getString(cursor.getColumnIndex(Contacts.LOOKUP_KEY)); String groupId = getGroupIdOfContact(lookupKey); if (targetGroupId.equals(groupId)){ //TODO. delete this contact } } } finally { if (cursor!=null) cursor.close(); } } </code></pre> <p>The above code has not tested but I think that basic idea would be same.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload