Android – how do I display and process the application’s contact details?

background

I'm not sure how it is called, but when you open the contact details screen of the contact application, you will see various applications that can be clicked to perform actions (such as calling and sending messages through Viber and WhatsApp), as follows:

problem

I don't know how these actions are invoked, so I can't find out how to investigate them. I try to search every social network and how to use it, but it seems to be a lot of effort and may not even work well in the future

I want to query these actions, display them, and process them for all applications displayed on the local contacts application

I tried

I tried to investigate the intention of being used and found that for Viber, this 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, but it is valid because I have tested it with real data. I also tried to actually print all contact databases and find the correct value (and mapping), but I didn't find it

In addition, I can't find how to find this information. My guess is that it should include queries for available mimetypes and check them on the specified contact (possibly using contact ID)

This problem

Given a contact (ID card or phone number), how do I display and perform the actions displayed on the contact details screen of the contact application?

resolvent:

If you from contactscontract.data.content_ Query all the contact information in the URI table and dump it to the log. You will see the original contacts in accounts such as com.whatsapp or com.viber. The data lines of these contacts include the data line vnd.android.cursor.item starting with mimetypes

For example, the WhatsApp data row might look like this:

TIMEOUT

When you click this action, you need to create the following intent:

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");

The application should have an activity registered to the mimeType, which will be in data.content_ Query 247 row ID in the URI table, obtain the configuration file ID from data1 and perform the requested operation

Specific fields (one of which is visible text, etc.) are defined in the contactsdatakind object of the application, but external applications are not easy to read, but according to my experience, most such applications use the same fields for the same behavior (for example, data3 is the action text displayed by the user)

Attachment: to get resources that do not belong to your application, you can use:

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>