I try the following code to remove contact with a specified number:
private void removeContact(Context context, String phone) {
//context.getContentResol
A better way to delete a contact is by removing all raw contacts using contact id
final ArrayList ops = new ArrayList();
final ContentResolver cr = getContentResolver();
ops.add(ContentProviderOperation
.newDelete(ContactsContract.RawContacts.CONTENT_URI)
.withSelection(
ContactsContract.RawContacts.CONTACT_ID
+ " = ?",
new String[] { allId.get(i) })
.build());
try {
cr.applyBatch(ContactsContract.AUTHORITY, ops);
int deletecontact = serialList.get(allId.get(i));
} catch (RemoteException e) {
e.printStackTrace();
} catch (OperationApplicationException e) {
e.printStackTrace();
}
//background_process();
ops.clear();
}
and dont forget to add permissions