To delete all contacts, use the following code:
ContentResolver cr = getContentResolver(); Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); while (cur.moveToNext()) { try{ String lookupKey = cur.getString(cur.getColumnIndex( ContactsContract.Contacts.LOOKUP_KEY)); Uri uri = Uri.withAppendedPath(ContactsContract. Contacts.CONTENT_LOOKUP_URI, lookupKey); System.out.println("The uri is " + uri.toString()); cr.delete(uri, null, null); } catch(Exception e) { System.out.println(e.getStackTrace()); } }
To delete a specific contact, change the request
cr.delete(uri, null, null);
Hope this helps!
source share