How to programmatically delete all contacts in the contact list on an Android phone

I want to delete all contacts on one button by clicking from my application, so that any good person can tell me how to programmatically delete all contacts from an Android android with just one click of a button? an answer would be greatly appreciated ...

In fact, I surfed after a couple of hours, but did not receive a corresponding answer. That's why I need to post my problem on this nice forum ... thanks to such a forum ....

+6
source share
2 answers

It is very simple, this code will delete all your contacts.

ContentResolver contentResolver = <your app context>.getContentResolver(); Cursor cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); while (cursor.moveToNext()) { String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)); Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey); contentResolver.delete(uri, null, null); } 

Done.

+23
source

Specify the permissions READ_CONTACTS and WRITE_CONTACTS in your AndroidManifest.xml.

Iterating through each contact and deleting each record: Content Providers

Contacts

Be careful when deleting contacts! Removing an aggregate contact deletes all compound raw contacts. Corresponding sync adapters will notice the deletion of their respective raw contacts and delete them from the repository on the rear panel.

+5
source

Source: https://habr.com/ru/post/894439/


All Articles