Skip to content Skip to sidebar Skip to footer

How To Show&handle Contact Details Intents Of Apps?

Background 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

Solution 1:

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.

For example a WhatsappData row might look like this:

_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 ...

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:

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

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.

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)

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

Drawableicon= getPackageManager().getApplicationIcon( PACKAGE_NAME );

EDIT

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.

For example, Whatsapp contacts.xml looks like this:

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

And Google Duo contacts.xml file is:

<ContactsAccountTypexmlns:android="http://schemas.android.com/apk/res/android"><ContactsDataKindandroid: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" /><ContactsDataKindandroid: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>

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

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

Post a Comment for "How To Show&handle Contact Details Intents Of Apps?"