I'm adding contacts with
ops.add(ContentProviderOperation.newInsert(
ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
.build());
ops.add(ContentProviderOperation.newInsert(
ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, contactName)
.build());
ops.add(ContentProviderOperation.newInsert(
ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, newPhone)
.build());
and later deleting them with
ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI)
.withSelection(ContactsContract.RawContacts._ID + "=?", new String[]{idRawContact}).build());
While debugging I found two issues as I reinsert same deleted name+number:
1) "standard" contacts phone app starts to list several identical entries for each.
2) numbers that have WhatsApp account appear in WhatsApp application, however they are not in WhatsApp account selection of contacts phone app (whereas at time of first insert number was added to that list) - also (obviously?) they stop to be selected via (only deleted enties are selected):
Cursor curRawContacts = contentResolver.query(ContactsContract.RawContacts.CONTENT_URI, null,
ContactsContract.RawContacts.ACCOUNT_TYPE + " = ? ", new String[]{"com.whatsapp"}, null);
Please advice if anything can be done to fix that - maybe deleting data from tables apart from rawcontacts? Can entries from rawcontacts be permanently deleted (not only setting ContactsContract.RawContacts.CONTACT_ID
= null
)?
Also, what contacts management application can select entries by accounts/types (google, whatsapp, sim1, etc) - one of my phones has such one, others do not and I failed to find such on Google Play.