code: 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;
      }
docs: Checks if the target package is installed on this device.
  @param context the context.
  @param targetPackage the target package name.
  @return {@code true} if installed, false otherwise.