How to check programmatically if an application is installed or not in Android?

后端 未结 15 1091
悲哀的现实
悲哀的现实 2020-11-22 05:51

We have installed applications programmatically.

  1. If the application is already installed in the device the application is open automatically.
  2. Otherwis
15条回答
  •  攒了一身酷
    2020-11-22 06:31

    Try this

    This code is used to check weather your application with package name is installed or not if not then it will open playstore link of your app otherwise your installed app

    String your_apppackagename="com.app.testing";
        PackageManager packageManager = getPackageManager();
        ApplicationInfo applicationInfo = null;
        try {
            applicationInfo = packageManager.getApplicationInfo(your_apppackagename, 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        if (applicationInfo == null) {
            // not installed it will open your app directly on playstore
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + your_apppackagename)));
        } else {
            // Installed
            Intent LaunchIntent = packageManager.getLaunchIntentForPackage(your_apppackagename);
            startActivity( LaunchIntent );
        }
    

提交回复
热议问题