Home > Net >  How does Android detect that phone has WhatsApp?
How does Android detect that phone has WhatsApp?

Time:12-16

I want to know how this feature technically works:

android contact screenshot

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 ?

CodePudding user response:

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.

CodePudding user response:

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;
}
  • Related