How can I delete a contact using the adb shell? I know the raw_contact_id of the contact.
I tried different ways but none with success.
To edit a contact I used the command
am start -a android.intent.action.EDIT content://contacts/people/8
and it worked.
But deleting it with
am start -a android.intent.action.DELETE content://contacts/people/8
does not work and showed me this error message:
Activity not started, unable to resolve Intent { act=android.intent.action.DELETE dat=content://contacts/people/8 flg=0x10000000 }
(flg=0x10000000 means FLAG_RECEIVER_FOREGROUND, I think it is set automatically.)
Do I have to set some flags? Or why does this not work?
A more fancy way is to simulate the process, how a normal user deletes the contact.
am start -a android.intent.action.VIEW content://contacts/people/8
input keyevent 22 # right button
input keyevent 22 # reach field in the right corner
input keyevent 66 # enter
input keyevent 20 # go down
input keyevent 20 # go down --> reached "Delete"
input keyevent 66 # enter
input keyevent 22 # button "Ok"
input keyevent 66 # enter
After clicking on the "Delete" button, the contact app always crashes (Contacts has been closed). Using these key events never worked on my emulator -- if I click on the buttons by hand (with my mouse), everything works…
Third way could be deleting the entries in the databases. This does not make sense for me, because then they are completely deleted -- if they are deleted the "normal" way, the contacts are still stored in some tables (like "deleted contacts").
The content://contacts
provider has been deprecated. You should be using content://com.android.contacts
instead:
$ adb shell content query --uri content://com.android.contacts/contacts
To remove contact (where's id = 1)
$ adb shell content delete --uri content://com.android.contacts/contacts/1
To remove all contacts at once
$ adb shell pm clear com.android.providers.contacts
User contributions licensed under CC BY-SA 3.0