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

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

    A cool answer to other problems. If you do not want to differentiate "com.myapp.debug" and "com.myapp.release" for example !

    public static boolean isAppInstalled(final Context context, final String packageName) {
        final List appsInfo = context.getPackageManager().getInstalledApplications(0);
        for (final ApplicationInfo appInfo : appsInfo) {
            if (appInfo.packageName.contains(packageName)) return true;
        }
        return false;
    }
    

提交回复
热议问题