如何在Android中通过ID打开名片
是否可以通过联系人 ID 打开 Android 联系人名片?它适用于电话号码。这是一个示例,如果我使用
Intent i = new Intent();
i.setAction(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
i.setData(Uri.fromParts("tel", "123456", null)); //<---- Change here from Phone to IDcontext.startActivity(i);
“但我想通过 ID 打开此联系人卡片”,例如,如果联系人的电话号码发生变化。
Is it possible to open an android contact card by contact's ID? It works with the phone-number. Here is an example, if I use
Intent i = new Intent();
i.setAction(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
i.setData(Uri.fromParts("tel", "123456", null)); //<---- Change here from Phone to IDcontext.startActivity(i);
But I want to open this contact card by ID, for example if the phone-number from the contact would change.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 ACTION_VIEW 并使用联系人 ID 构建联系人 URI,或者使用联系人查找 URI(如果您已有)(首选)。
use ACTION_VIEW and either build a contact URI using the contact ID or use the contact lookup URI if you already have it (preferred).
您将使用以下 URI:
您可以通过查看 CONTENT_LOOKUP_URI 的 API 文档。
You would use the following URI:
You will find more details about how this URI works by looking at the API documentation for CONTENT_LOOKUP_URI.
我试图使用此处列出的方法打开联系人卡片,但不知何故,联系人活动在打开后立即关闭。
看来联系活动不接受我的旧内容 URI。
我使用
ContactsContract.Contacts
类的getLookupUri (long contactId, String LookupKey)
方法解决了这个问题,以获得正确的内容 uri https://developer.android.com/reference/android/provider /ContactsContract.Contacts.html#getLookupUri(long, java.lang.String)因此,打开联系人卡片的代码变为:
I was trying to open a contact card using the listed here methods, but somehow the contacts activity was closing immediately after it was opening.
it seemed that the contact activity didn't accept my old content uri.
I resolved this problem using the
getLookupUri (long contactId, String lookupKey)
method ofContactsContract.Contacts
class for obtaining the right content uri https://developer.android.com/reference/android/provider/ContactsContract.Contacts.html#getLookupUri(long, java.lang.String)So the code for opening a contact card becomes: