Returns {@code true} if the application is installed.

@param context    The instance of {@link android.content.Context}.
@param appPackage The package of the checked application.
@return {@code true} if the application is installed, false otherwise.
345427
public static boolean isInstalled(@NonNull final Context context,
                                      @NonNull final String appPackage) {
        try {
            return context.getPackageManager().getApplicationInfo(appPackage, 0) != null;
        } catch (PackageManager.NameNotFoundException ignore) {
            // ignore
        }
        return false;
    }
1254258
protected boolean checkActionPackages(String classPackageName) {
		if (actionPackages != null) {
			for (String packageName : actionPackages) {
				String strictPackageName = packageName + ".";
				if (classPackageName.equals(packageName) || classPackageName.startsWith(strictPackageName))
					return true;
			}
		}
		return false;
	}
1373696
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
    public static boolean hasLowLatencyAudioFeature(Context context) {
        return hasLowLatencyAudioFeature(context.getPackageManager());
    }
986852
public static boolean launchAppForPackage(final Context context, final String packageName) {
        try {
            final PackageManager packageManager = context.getPackageManager();
            final Intent intent = packageManager.getLaunchIntentForPackage(packageName);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            context.startActivity(intent);
            return true;
        } catch (Exception ex) {
            Log.e("Caffeine", "Failed to launch application for package name [" + packageName + "]", ex);
            return false;
        }
    }
663860
private void buildApplicationData(Context context) throws JSONException {
        app = new JSONObject();
        app.put("package", context.getPackageName());
        try {
            PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            app.put("versionCode", info.versionCode);
            app.put("versionName", info.versionName);
            // TODO firstInstallTime and lastUpdate
        } catch (NameNotFoundException e) {
            // Cannot happen as we're checking a know package.
        }
    }
609927
private boolean validateServiceIntent(Context context, Intent intent) {
        ResolveInfo resolveInfo = context.getPackageManager().resolveService(intent, 0);
        if (resolveInfo == null) {
            return false;
        }

        return validateAppSignatureForPackage(context, resolveInfo.serviceInfo.packageName);
    }
114953
public static boolean isSystemPackage(@Nullable @CheckForNull Package aPackage) {
    if (aPackage == null) {
      return false;
    }
    return runAsSystem(
        () ->
            aPackage.getId().equals(PACKAGE_SYSTEM)
                || (aPackage.getRootPackage() != null
                    && aPackage.getRootPackage().getId().equals(PACKAGE_SYSTEM)));
  }
280624
private static int getAppVersion(Context context) {
        try {
            PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0);
            return packageInfo.versionCode;
        } catch (NameNotFoundException e) {
            // should never happen
            throw new RuntimeException("Coult not get package name: " + e);
        }
    }
804008
public static boolean isPackageInstalled(Context context, String targetPackage) {
        PackageManager manager = context.getPackageManager();
        Intent intent = new Intent();
        intent.setPackage(targetPackage);
        return manager.resolveActivity(intent, 0) != null;
    }
898793
public static boolean isPackageInstalled(Context context, String packageName) {
		try {
			context.getPackageManager().getApplicationInfo(packageName, 0);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
676219
void putApp(Context context) {
    try {
      PackageManager packageManager = context.getPackageManager();
      PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
      Map<String, Object> app = createMap();
      putUndefinedIfNull(app, APP_NAME_KEY, packageInfo.applicationInfo.loadLabel(packageManager));
      putUndefinedIfNull(app, APP_VERSION_KEY, packageInfo.versionName);
      putUndefinedIfNull(app, APP_NAMESPACE_KEY, packageInfo.packageName);
      app.put(APP_BUILD_KEY, String.valueOf(packageInfo.versionCode));
      put(APP_KEY, app);
    } catch (PackageManager.NameNotFoundException e) {
      // ignore
    }
  }
900361
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
    public static boolean hasBluetoothLEFeature(Context context) {
        return hasBluetoothLEFeature(context.getPackageManager());
    }
481726
private void installPackage() {
        AndPermission.with(this)
            .install()
            .file(new File(Environment.getExternalStorageDirectory(), "android.apk"))
            .rationale(new InstallRationale())
            .onGranted(new Action<File>() {
                @Override
                public void onAction(File data) {
                    // Installing.
                }
            })
            .onDenied(new Action<File>() {
                @Override
                public void onAction(File data) {
                    // The user refused to install.
                }
            })
            .start();
    }
258931
private boolean isFacebookAppInstalled() {
        boolean isInstalled = false;
        try {
            // An exception will be thrown if the package is not found.
            mContext.getPackageManager().getApplicationInfo(FACEBOOK_APP_PACKAGE, 0);
            isInstalled = true;
        } catch (PackageManager.NameNotFoundException e) {
            // Do nothing.
        }
        return isInstalled;
    }
245608
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
    public static boolean hasAppWidgetFeature(Context context) {
        return hasAppWidgetFeature(context.getPackageManager());
    }
689640
@TargetApi(Build.VERSION_CODES.FROYO)
    public static boolean hasNetworkLocationFeature(Context context) {
        return hasNetworkLocationFeature(context.getPackageManager());
    }
4596
public boolean shouldScanPackage(String pkg)
    {
        // assume an empty string if it wasn't specified
        if (pkg == null)
        {
            pkg = "";
        }
        WindupJavaConfigurationModel configuration = getJavaConfigurationModel(getGraphContext());
        for (PackageModel pkgModel : configuration.getExcludeJavaPackages())
        {
            String excludePkg = pkgModel.getPackageName();
            if (pkg.startsWith(excludePkg))
            {
                return false;
            }
        }

        // if the list is empty, assume it is intended to just accept all packages
        if (!configuration.getScanJavaPackages().iterator().hasNext())
        {
            return true;
        }

        for (PackageModel pkgModel : configuration.getScanJavaPackages())
        {
            String includePkg = pkgModel.getPackageName();
            if (pkg.startsWith(includePkg))
            {
                return true;
            }
        }

        return false;
    }