Delete contact via adb

1

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.

  1.   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?

  2. 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…

  3. 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").

android
android-intent
adb
keyevent
asked on Stack Overflow May 12, 2014 by CFP • edited Aug 29, 2015 by Brian Tompsett - 汤莱恩

1 Answer

0

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
answered on Stack Overflow Nov 10, 2020 by The Mauler • edited Nov 13, 2020 by The Mauler

User contributions licensed under CC BY-SA 3.0