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 calling and sending messages via Viber and WhatsApp) as such:
The problem
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.
What I've tried
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");
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.
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).
The question
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 ?
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 likecom.whatsapp
orcom.viber
, that have data rows withmimetypes
that begin withvnd.android.cursor.item
.For example a
Whatsapp
Data
row might look like this:So when your code sees such
Data
rows, it should display to the user the app icon of the appcom.whatsapp
(account_type
) with the textMessage +1 123-456-789
(data3
) and you can also display other info like app nameWhatsapp
(data2
).When that action is clicked, you need to create an intent like this:
The app should have an
Activity
that registered to that mimetype, that will query theData.CONTENT_URI
table for the247
row-id, get the profile id fromdata1
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: