通过ADB删除联系人 [英] Delete contact via adb
问题描述
如何使用adb shell删除联系人?我知道联系人的raw_contact_id.
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
它奏效了.
但是用
am start -a android.intent.action.DELETE content://contacts/people/8
不起作用,并向我显示此错误消息:
does not work and showed me this error message:
活动尚未开始,无法解决意图{act = android.intent.action.DELETE dat = content://contacts/people/8 flg = 0x10000000}
Activity not started, unable to resolve Intent { act=android.intent.action.DELETE dat=content://contacts/people/8 flg=0x10000000 }
(flg = 0x10000000表示FLAG_RECEIVER_FOREGROUND,我认为它是自动设置的.)
(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").
推荐答案
content://contacts
提供程序已被弃用.您应该改用content://com.android.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
要删除联系人(id = 1)
To remove contact (where's id = 1)
$ adb shell content delete --uri content://com.android.contacts/contacts/1
要一次删除所有联系人
$ adb shell pm clear com.android.providers.contacts
这篇关于通过ADB删除联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!