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

后端 未结 15 1082
悲哀的现实
悲哀的现实 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:52

    This code checks to make sure the app is installed, but also checks to make sure it's enabled.

    private boolean isAppInstalled(String packageName) {
        PackageManager pm = getPackageManager();
        try {
            pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
            return pm.getApplicationInfo(packageName, 0).enabled;
        }
        catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return false;
        }
    }
    

提交回复
热议问题