如何显示和处理应用程序的联系详细信息意图? [英] How to show&handle contact details intents of apps?

查看:71
本文介绍了如何显示和处理应用程序的联系详细信息意图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定如何调用,但是当您打开通讯录应用程序的联系人详细信息"屏幕时,您会看到在那里可以单击执行各种操作(例如通过Viber和WhatsApp调用和发送消息)的各种应用程序:

Not sure how it's called, but when you open the contact-details screen of the contacts app, you see various apps there that you can click to perform actions on (such as calling and sending messages via Viber and WhatsApp) as such:

我不知道这些动作的调用方式,所以我不知道如何进行调查.我尝试搜索每个社交网络以及如何使用它,但是这似乎需要很多努力,甚至将来可能无法正常工作.

I don't know how those actions are called, so I can't find out how to investigate them. I tried searching for each social network, how to use it, but this seems like a lot of effort that might not even work well in the future.

我希望针对本机联系人应用程序中显示的所有应用程序查询这些动作,显示它们并进行处理.

I wish to query those actions, show them, and handle them, for all of the apps that are shown on the native contacts app.

我试图调查正在使用的意图,发现对于Viber,这是可用于消息的内容:

I tried to investigate the intents that are being used, and found that for Viber, this is what can be used for messages:

    intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/data/"+id));
    intent.setPackage("com.viber.voip");

但是,我不知道这个"id"是什么,只是因为我已经用真实数据对其进行了测试,所以它不起作用.我还尝试打印所有的联系人数据库,以找到要使用的正确值(和映射),但是我没有找到它.

However, I don't know what this "id" is, only that it works because I've tested it with real data. I also tried to actually print all of the contacts database, to find the correct value to use (and the mapping), but I didn't find it.

此外,我找不到应如何找到此信息.我的猜测是,它可能应该包含一个查询可用的模仿类型,并在指定的联系人上检查它们(可能使用联系人ID).

Also, I can't find how this information should have been found. My guess is that it should probably include a query of the available mimetypes, and check them on the specified contact (probably using contact id).

给出联系人(ID或电话号码),如何显示和执行联系人应用程序的联系人详细信息"屏幕上显示的操作?

Given a contact (id or phone number), how can I show and perform the operation as shown on contact-details screen of the contacts app ?

推荐答案

如果您从ContactsContract.Data.CONTENT_URI表中查询所有联系人的信息,并将其转储到日志中,您将在com.viber,它们具有以vnd.android.cursor.item开头的mimetypes数据行.

If you query for all that contact's info from the ContactsContract.Data.CONTENT_URI table, and dump it to log, you'll see raw-contacts in accounts like com.whatsapp or com.viber, that have data rows with mimetypes that begin with vnd.android.cursor.item.

例如,Whatsapp Data行可能看起来像这样:

For example a Whatsapp Data row might look like this:

_id:247
account_type:com.whatsapp
模仿类型:vnd.android.cursor.item/vnd.com.whatsapp.profile
显示名称:鲍勃
raw_contact_id:62
数据1:1123456789@s.whatsapp.net
数据2:WhatsApp
data3:消息+1 123-456-789
//其他信息...

_id: 247
account_type: com.whatsapp
mimetype: vnd.android.cursor.item/vnd.com.whatsapp.profile
display_name: Bob
raw_contact_id: 62
data1: 1123456789@s.whatsapp.net
data2: WhatsApp
data3: Message +1 123-456-789
// other info ...

因此,当您的代码看到这样的Data行时,它应向用户显示应用程序com.whatsapp(account_type)的应用程序图标,并带有文本Message +1 123-456-789(data3),并且您也可以显示其他信息,例如应用名称Whatsapp(data2).

So when your code sees such Data rows, it should display to the user the app icon of the app com.whatsapp (account_type) with the text Message +1 123-456-789 (data3) and you can also display other info like app name Whatsapp (data2).

点击该操作后,您需要创建一个这样的意图:

When that action is clicked, you need to create an intent like this:

Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, 247);
Intent i = new Intent(Intent.ACTION_VIEW, uri);
i.setType("vnd.android.cursor.item/vnd.com.whatsapp.profile");

应用程序应具有注册到该模仿类型的Activity,它将在Data.CONTENT_URI表中查询247行ID,从data1获取配置文件ID并执行请求的操作.

The app should have an Activity that registered to that mimetype, that will query the Data.CONTENT_URI table for the 247 row-id, get the profile id from data1 and perform the action requested.

特定字段(其中一个是可见文本等)在应用程序的ContactsDataKind对象中定义,但外部应用程序不容易读取,但是以我的经验,大多数此类应用程序都使用相同的字段相同的行为(例如data3是用户显示的操作文本)

The specific fields (which one is the visible text, etc.) are defined in a ContactsDataKind object in the app, but it's not that easily read by external apps, but in my experience most such apps use the same fields for the same behavior (e.g. data3 is the user displayed action text)

PS
要获取不是您自己的应用程序的资源,可以使用以下方法:

P.S.
To get the resource of an app that is not yours, you can use this:

Drawable icon = getPackageManager().getApplicationIcon( PACKAGE_NAME );

编辑

每个要同步联系人并希望由Contacts应用程序执行特定于应用程序操作的应用程序都需要在res/xml/contacts.xml下创建一个contact.xml文件,该应用程序需要通过getPackageManager()(或其他方式)进行访问,因此联系人呈现应用将能够读取并识别该应用的特定MIMETYPES和字段映射.

Each app that syncs contacts and wish to be presented by Contacts apps with app-specific actions will need to create a contacts.xml file under res/xml/contacts.xml that app needs to be accessible via getPackageManager() (or other means) so the contact presenting app will be able to read it and recognize the app's specific MIMETYPES and field mappings.

例如,Whatsappcontacts.xml如下所示:

For example, Whatsapp contacts.xml looks like this:

<ContactsSource
  xmlns:android="http://schemas.android.com/apk/res/android">
    <ContactsDataKind android:icon="@mipmap/icon" android:mimeType="vnd.android.cursor.item/vnd.com.whatsapp.profile" android:summaryColumn="data2" android:detailColumn="data3" android:detailSocialSummary="true" />
    <ContactsDataKind android:icon="@mipmap/icon" android:mimeType="vnd.android.cursor.item/vnd.com.whatsapp.voip.call" android:summaryColumn="data2" android:detailColumn="data3" />
    <ContactsDataKind android:icon="@mipmap/icon" android:mimeType="vnd.android.cursor.item/vnd.com.whatsapp.video.call" android:summaryColumn="data2" android:detailColumn="data3" />
</ContactsSource>

Google Duo的contacts.xml文件为:

And Google Duo contacts.xml file is:

<ContactsAccountType
  xmlns:android="http://schemas.android.com/apk/res/android">
    <ContactsDataKind android:icon="@drawable/product_logo_duo_color_48" android:mimeType="vnd.android.cursor.item/com.google.android.apps.tachyon.phone" android:summaryColumn="data4" android:detailColumn="data5" android:detailSocialSummary="true" />
    <ContactsDataKind android:icon="@drawable/duo_audio_icon_vector" android:mimeType="vnd.android.cursor.item/com.google.android.apps.tachyon.phone.audio" android:summaryColumn="data4" android:detailColumn="data5" android:detailSocialSummary="true" />
</ContactsAccountType>

在此处查看官方文档: https://developer.android. com/guide/topics/providers/contacts-provider#ContactsFile

See official docs here: https://developer.android.com/guide/topics/providers/contacts-provider#ContactsFile

但是,如果您不打算支持世界上的所有单个应用程序,而只是选择一些精选的应用程序列表(如Whatsapp/Duo),则将它们映射起来会更容易在您的应用中手动输入字段

However, if you're not planning on supporting EVERY single app in the world, rather just some hand-picked list of apps like Whatsapp / Duo, it would be way easier just to map those fields manually in your app

这篇关于如何显示和处理应用程序的联系详细信息意图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆