javascript 如何检查 Android 上是否安装了 Flash 播放器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4914663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 15:21:09  来源:igfitidea点击:

How to check if the Flash players is installed on Android

javascriptandroidbrowserflash

提问by STeN

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?

如果从 Android Market 下载并安装了 Adob​​e Flash Player 10.1 (https://market.android.com/details?id=com.adobe.flashplayer),如何在 Android 网络浏览器中轻松检查 Javascript?

--

——

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.

更新:感谢回复,但我需要Javascript的检查代码,因为我正在做基于网络(HTML/Javascript/CSS)的解决方案,而不是本机 Java 应用程序。Web 应用程序的一小部分是在 Flex 中完成的,因此 .swf 文件显示在<div>元素中,但在此之前我想检查是否安装了 Flash Player。

回答by Lior

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

是否有任何特殊原因需要检查 Javascript 而不是 Java 代码?

From Java code, you can do something like this:

从 Java 代码中,您可以执行以下操作:

    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.

在我的 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.

如果您想知道我从哪里获取 com.adobe.flashplayer.FlashExpandableFileChooser 类名,我只是从 Flash 播放器的 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 hereon how to call this code from your JavaScript code. Specifically look at the setJavaScriptInterface method

您可以按照此处有关如何从 JavaScript 代码调用此代码的说明进行操作。具体看setJavaScriptInterface方法

To detect directly from JavaScript, use this snippet:

要直接从 JavaScript 检测,请使用以下代码段:

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;
    }
}

回答by ldx

You can use PackageManager:

您可以使用包管理器:

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

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

Check out the getInstalledApplications() method.

查看 getInstalledApplications() 方法。

回答by Jawad Zeb

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;
    }