-4

How to check if app is installed or not on phone. If the app is installed, open the app, otherwise open the appstore link to download the app. If the app is already there, I used the following code.

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("package name");
startActivity(LaunchIntent);
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
amol junghare
  • 73
  • 1
  • 1
  • 9
  • 3
    Does this answer your question? [Check if application is installed - Android](https://stackoverflow.com/questions/18752202/check-if-application-is-installed-android) – Roshana Pitigala Jan 05 '22 at 11:49
  • private boolean isPackageInstalled(String packageName, PackageManager packageManager) { try { packageManager.getPackageInfo(packageName, 0); return true; } catch (PackageManager.NameNotFoundException e) { return false; } } It checked whether it is present or not but it will not redirect to the playstore link. – amol junghare Jan 05 '22 at 13:00
  • Search search search... [How to open the Google Play Store directly from my Android application?](https://stackoverflow.com/a/11753070/2408342) – Roshana Pitigala Jan 05 '22 at 13:57

1 Answers1

0

Checking if app is installed having package name:

public static final String PACKAGE_NAME = "com.__.__";

    public static boolean isAppInstalled(Context context) {
        PackageManager packageManager = context.getPackageManager();
        Intent intent = new Intent(Intent.ACTION_VIEW);
        if (intent.resolveActivity(packageManager) != null) {
            try {
                packageManager.getPackageInfo(PACKAGE_NAME, PackageManager.GET_ACTIVITIES);
                return true;
            } catch (PackageManager.NameNotFoundException ignore) {

            }
        }
        return false;
    }

Open Play Market having package name:

try {
    startActivity(new Intent(Intent.ACTION_VIEW, 
         Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(Intent.ACTION_VIEW, 
        Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
Marina
  • 317
  • 4
  • 11