Answer the question
In order to leave comments, you need to log in
Why does not remove the number from the contact?
I am making a contact book, it is necessary to implement the removal of a phone number from a contact. On the stack, they advised me the code:
private final String queryPhone = ContactsContract.Contacts.Data.RAW_CONTACT_ID + "=? AND " + ContactsContract.Contacts.Data.MIMETYPE + "='"
+ ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "'" + " AND ";
private final String queryByNumber = ContactsContract.CommonDataKinds.Phone.NUMBER + "=?";
public void removePhoneByNumber(Long contactId, String phoneNumber) {
ArrayList<ContentProviderOperation> os = new ArrayList();
String[] phoneArgs = new String[] {String.valueOf(contactId), phoneNumber};
os.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
.withSelection(queryPhone + queryByNumber, phoneArgs)
.build());
try {
getContentResolver().applyBatch(ContactsContract.AUTHORITY, os);
}
catch (RemoteException e) {
e.printStackTrace();
}
catch (OperationApplicationException e) {
e.printStackTrace();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question