简体   繁体   中英

How does Android detect that phone has WhatsApp?

I want to know how this feature technically works:

安卓联系人截图

As far as I understand, there is no official API to check it for now. Before v 2.43 API version there was an official way to check via /v1/contacts API of WhatsApp Business. But now it doesn't work.

So how do they do it now?

Through their AndroidManifest.xml . Apps declare which Intents they're able to handle and there's one for making calls / sending SMS. Just call queryIntentActivities() on an instance of PackageManager , given an ACTION_{WHATEVER_FEATURE_YOU_WANT_TO_CHECK} Intent configured. This will give you a list of all the matches that would appear as if you tried to make a chooser.

You can check by package name of WhatsApp.

boolean isAppInstalled = appInstalledOrNot("com.whatsapp");  

Using PackageManager ,

private boolean appInstalledOrNot(String packageName) {
    PackageManager packageManagerm = getPackageManager();
    try {
        packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {}
    return false;
}

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