How to check if Flash is installed?

I use this snippet to check if the application / action is installed:

    public static boolean isIntentAvailable(Context context, String action) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action);
    List<ResolveInfo> list =
            packageManager.queryIntentActivities(intent,
                    PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

public static boolean isScanAvailable(Context context) {
    return isIntentAvailable(context, "com.google.zxing.client.android.SCAN");
}

In the above example, it checks to see if a barcode scanner application is installed, which works fine. However, if I try to check Adobe Flashplayer with com.adobe.flashplayer, it does not work and always returns false.

Is there a better / more reliable way to test Flash?

+3
source share
1 answer

Wow yeah My code above checks for an Intent that doesn't work for flashplayer (I don't think of any public intent).

A more obvious way would be to simply use getPackageInfo()one that works fine:

    public static boolean isFlashAvailable(Context context) {
    String mVersion;
    try {
        mVersion = context.getPackageManager().getPackageInfo(
                "com.adobe.flashplayer", 0).versionName;
          Log.d("Flash", "Installed: " + mVersion);
          return true;
    } catch (NameNotFoundException e) {
          Log.d("Flash", "Not installed");
          return false;
    }
   }

( )

+14

Source: https://habr.com/ru/post/1780634/


All Articles