-1

I want to show Whatsapp is not installed when users click on "Share On Whatsapp" button. i got policy violation from adMob, if users have installed Whatsapp all works fine but if users don't have Whatsapp then App crashes on Share click, this is my code:

public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url != null && url.startsWith("whatsapp://")) {
                view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                return true;
            }

Thanks

Chand Ninder
  • 161
  • 5
  • 19

2 Answers2

1

You can check this by whether the specific package is installed or not by using context of package manager.

private boolean isPackageInstalled(String packageName, PackageManager packageManager) {
try {
    packageManager.getPackageInfo(packageName, 0);
    return true;
} catch (PackageManager.NameNotFoundException e) {
    return false;
   }
} 

Call above method by

PackageManager pm = context.getPackageManager();
boolean isInstalled = isPackageInstalled("com.whatsapp",pm);
Ranjeet Chouhan
  • 686
  • 5
  • 13
0

try to check at first that WhatsApp is installed on device. HERE you have some guide

packageName to check is "com.whatsapp", same as id param in Google Play url

https://play.google.com/store/apps/details?id=com.whatsapp

snachmsm
  • 17,866
  • 3
  • 32
  • 74