简体   繁体   中英

How does the native android contacts app cater for intents to apps, such as whatsapp

WhatsApp recently added the call feature. Before this, there was only one option when viewing a contact, that was to message the contact. Now there is the option to message or call a contact. Did WhatsApp add this entry to the ContactsContract, or did Google modify the contacts app to cater for WhatsApp? I am trying to make a custom contacts app, but I don't understand how to create links to apps from within this custom contacts app.

I have read this question,

How to get contacts which are used in whatsapp or other application in android

But the solution isn't generic enough. I want to make a contacts app that doesn't have the names of applications hard coded in.

An Android app can advertise in it's manifest it handles implicit intent for a given action (see Receiving an implicit intent ). In this case, a dial action .

And to your practical question - you can use the PackageManager to query which Activities can handle an intent (in this case, an intent with ACTION_DIAL action), and use the PackageManager to get their name, icon, etc.

In WhatsApp case, you would like to know which contacts are WhatsApp users, but WhatsApp does not have an API or it's own ContentProvider. This 2014 blog post solution might be still valid, haven't checked.

Every app can only specify what type of uri scheme they can handle like sms:// or tel:// . For clearification, Apps cann't add entry of itself in some other apps.

In your Example case:
The Contact app itself implemented in such a way that it list all apps which can handle sms:// or tel:// type of uri scheme . As the older version of WhatsApp can only handle sms:// uri scheme that's why Contact app only list SMS/message option.
Also with calling feature in WhatsApp they added support for handling tel:// uri scheme that's why Contact app also shows the calling option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM