Skip to content Skip to sidebar Skip to footer

Launching An Application If Installed Or Redirect To Google Play

Until now I was using this code to launch a 3rd party application if installed or redirect to Google Play to download it if not installed already: Intent intent = Intent intent = g

Solution 1:

you can use a try catch to see if the package name exists

try {
    PackageManager pm=getPackageManager();
    PackageInfo info=pm.getPackageInfo("com.package.address",PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
    //launch play store
}

Solution 2:

A complete working solution

Intentintent= getPackageManager().getLaunchIntentForPackage("slidy.whatsappsticker");
            if (intent != null)
            {
                /* we found the activity now start the activity */
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                showInterstitial();
            }
            else {
                try {
                    PackageManagerpm= getPackageManager();
                    PackageInfoinfo= pm.getPackageInfo("com.package.name", PackageManager.GET_META_DATA);
                } catch (PackageManager.NameNotFoundException e) {
                    //launch play store
                    startActivity(newIntent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.package.name")));
                }
            }

Post a Comment for "Launching An Application If Installed Or Redirect To Google Play"