endzeit
endzeit

Reputation: 705

How to check if Flash is installed?

i'm using this snippet to check if an app/activity 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 if the Barcode Scanner App is installed, which works just fine. However, if i try to check for the Adobe Flashplayer using com.adobe.flashplayer it doesn't work and always returns false.

Is there a better / more reliable method to check for Flash?

Upvotes: 3

Views: 2376

Answers (1)

endzeit
endzeit

Reputation: 705

Uhm yeah. My code posted above does Intent checking which isn't working for the flashplayer (no public intents i guess).

The more obvious way would be to just use getPackageInfo() which works just 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;
    }
   }

(As an added bonus we get the exact version number too)

Upvotes: 14

Related Questions