3

how can I easily check in Javascript in the Android web browser if the Adobe Flash Player 10.1 (https://market.android.com/details?id=com.adobe.flashplayer) was downloaded from Android Market and installed?

--

Update: Thanks for replies, but I need the check code for Javascript, since I am doing the web based (HTML/Javascript/CSS) solution, not native Java application. Small part of the web application is done in Flex, so .swf file is displayed in <div> element, but prior of doing that I would like to check if Flash Player is installed or not.

Sampson
  • 265,109
  • 74
  • 539
  • 565
STeN
  • 6,262
  • 22
  • 80
  • 125
  • If you have updates, please edit them into your original question. I've taken the liberty of doing this for you this time. Thank you. – Sampson Feb 07 '11 at 14:20

3 Answers3

4

Is there any special reason you need to check from Javascript and not from the Java code?

From Java code, you can do something like this:

    Intent intent = new Intent();

    intent.setComponent(new ComponentName("com.adobe.flashplayer", "com.adobe.flashplayer.FlashExpandableFileChooser"));
    PackageManager pm = getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
    if (activities != null && activities.size() > 0) {
        Toast.makeText(this, "Flash is installed!", Toast.LENGTH_LONG).show();
    }
    else {
        Toast.makeText(this, "Flash not installed!", Toast.LENGTH_LONG).show();
    }

Works well on my HTC Desire.

If you're wondering where did I take the com.adobe.flashplayer.FlashExpandableFileChooser class name from, I simply took it from the Flash player's AndroidManifest.xml.

It looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:versionCode="101106016"
        android:versionName="10.1.106.16"
        package="com.adobe.flashplayer"
        >
        <application
                android:label="Adobe Flash Player 10.1"
                android:icon="@7F020000"
                >
                <activity
                        android:name="com.adobe.flashplayer.FlashExpandableFileChooser"
                        >
                        <intent-filter
                                >
                                <action
                                        android:name="android.intent.action.MAIN"
                                        >
                                </action>
                                <category
                                        android:name="android.intent.category.DEFAULT"
                                        >
                                </category>
                                <category
                                        android:name="FlashExpandableFileChooser"
                                        >
                                </category>
                        </intent-filter>
                </activity>
                <service
                        android:name="com.adobe.flashplayer.FlashPaintSurface"
                        >
                        <intent-filter
                                >
                                <action
                                        android:name="android.webkit.PLUGIN"
                                        >
                                </action>
                        </intent-filter>
                        <meta-data
                                android:name="type"
                                android:value="native"
                                >
                        </meta-data>
                </service>
        </application>
        <uses-permission
                android:name="android.webkit.permission.PLUGIN"
                >
        </uses-permission>
        <uses-sdk
                android:minSdkVersion="8"
                android:targetSdkVersion="5"
                android:maxSdkVersion="10"
                >
        </uses-sdk>
</manifest>

You can follow the instructions here on how to call this code from your JavaScript code. Specifically look at the setJavaScriptInterface method

To detect directly from JavaScript, use this snippet:

flashInstalled = false;
if (navigator.plugins && navigator.plugins.length) {
  for (n = 0; n < navigator.plugins.length; n++) {
    if (navigator.plugins[n].name.indexOf('Shockwave Flash') != -1) {
        flashInstalled = true;
        break;
    }
}
Lior
  • 7,845
  • 2
  • 34
  • 34
  • Hi, thanks for reply, but I need Javascript code snippet, since I am doing the web application - see my answer below. – STeN Feb 07 '11 at 06:34
  • I added pure JavaScript code to the answer. It should work for any webKit based browser (And generally any netscape compatible browser). – Lior Feb 08 '11 at 06:45
  • See [stackoverflow](http://stackoverflow.com/questions/4458930/how-to-check-if-flash-is-installed/4518006#4518006) for a Java code answer that doesn't require knowledge of the "FlashExpandableFileChooser" name. – resnbl Apr 09 '11 at 09:52
1

You can use PackageManager:

http://developer.android.com/reference/android/content/pm/PackageManager.html

Check out the getInstalledApplications() method.

ldx
  • 3,984
  • 23
  • 28
0

Another approach to do the same work

 boolean flashInstalled = false;
    try {
      PackageManager pm = getPackageManager();
      ApplicationInfo ai = pm.getApplicationInfo("com.adobe.flashplayer", 0);
      if (ai != null)
        flashInstalled = true;
    } catch (NameNotFoundException e) {
      flashInstalled = false;
    }
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300