newDelete
method with ContentProvider does not work for me . It deletes all the information in the contact, but leaves the contact empty (null null) in your phonebook.
This is why I had to use ContentResolver with the delete
method.
I wanted to delete contacts created using my application using SOURCE_ID
.
I set CALLER_IS_SYNCADAPTER
to true
.
So this is how I dealt with this:
Uri contactUri = RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build(); String whereClause = RawContacts.SOURCE_ID + " = ?"; String[] args = new String[]{contactId}; int deletedRawContacts = context.getContentResolver().delete(contactUri, whereClause, args); if (deletedRawContacts > 0) { Log.d(TAG, "Delete OK"); } else { Log.d(TAG, "Nothing to delete"); }
source share