android - 亚行 shell : Add contacts with extras

标签 android shell android-intent android-contacts

要通过 adb shell 添加联系人,我使用命令

am start -a android.intent.action.INSERT -t vnd.android.cursor.dir/contact

以及更多信息

-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE>
Add string data as a key-value pair. 

所以例如号码为 123-456 的联系人“Donald Duck”的创建者为

am start -a android.intent.action.INSERT -t vnd.android.cursor.dir/contact -e name 'Donald Duck' -e phone 123-456

电话簿有 12 种 mimetype:

_id: mimetype
1: vnd.android.cursor.item/email_v2
2: vnd.android.cursor.item/im
3: vnd.android.cursor.item/nickname
4: vnd.android.cursor.item/organization
5: vnd.android.cursor.item/phone_v2
6: vnd.android.cursor.item/sip_address
7: vnd.android.cursor.item/name
8: vnd.android.cursor.item/postal-address_v2
9: vnd.android.cursor.item/identity
10: vnd.android.cursor.item/photo
11: vnd.android.cursor.item/group_membership
12: vnd.android.cursor.item/website

对于电子邮件地址,它是“email”,对于名称,它是“name”,对于“phone_v2”,它是电话。 但我没有找到任何适用于例如“邮政地址”、“组织”或“网站”。

我怎样才能知道添加这些额外信息需要哪个EXTRA_KEY?

最佳答案

找到了。在!难以置信的清晰且安排良好的 Android 开发文档中! 😒 来自http://developer.android.com/reference/android/provider/ContactsContract.Intents.Insert.html#POSTAL :

public static final String POSTAL

The extra field for the contact postal address.

Type: String

Constant Value: "postal"

交互式示例(如果您有可用的 dialog 命令),在我本地的 debian chroot @ /usr/local/bin/android.add 中:

#!/bin/sh
/system/bin/am start -a android.intent.action.INSERT -t vnd.android.cursor.dir/contact -e name "$(dialog --stdout --inputbox 'Contact Name' 0 0)" -e postal "$(dialog --stdout --inputbox 'Postal Address' 0 0)" -e phone "$(dialog --stdout --inputbox 'Phone Number' 0 0)" -e email "$(dialog --stdout --inputbox 'Email' 0 0)"

关于android - 亚行 shell : Add contacts with extras,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23563703/

相关文章:

java - 发现名称 : getText 存在冲突的 getter

java - 主菜单上的多个 Intent

android - 将带有 ACCOUNT_TYPE_LOCAL 的日历添加到 Android 4 会导致其日历崩溃

shell - 如何处理 JMESPath 包含可能为空的属性的过滤器?

php - 无法在 AFS 的 linux 终端上更改 http 写入权限?

python - 如何在 Python 中运行上下文感知命令?

java - 以 Intent 开始新 Activity 会抛出可序列化的异常

java - 为什么 Image 可以返回到之前的 Activity,但不能返回到新的 Activity

Android 2.2 - WebView,如何打开里面有<video>标签的网站?

android - 如何显示/隐藏 ListView 元素?