Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript在android上运行本机视频播放器?_Javascript_Android - Fatal编程技术网

如何使用javascript在android上运行本机视频播放器?

如何使用javascript在android上运行本机视频播放器?,javascript,android,Javascript,Android,是否可以从网络浏览器点击按钮或链接启动android本机播放器? 我不想在网络浏览器中使用html5视频标签来播放它 您可以使用WebView进行此操作。下面是一个代码示例,用于显示来自web页面的toast public class WebAppInterface { Context mContext; /** Instantiate the interface and set the context */ WebAppInterface(Context c) {

是否可以从网络浏览器点击按钮或链接启动android本机播放器? 我不想在网络浏览器中使用html5视频标签来播放它

您可以使用WebView进行此操作。下面是一个代码示例,用于显示来自web页面的toast

public class WebAppInterface {
    Context mContext;

    /** Instantiate the interface and set the context */
    WebAppInterface(Context c) {
        mContext = c;
    }

    /** Show a toast from the web page */
    @JavascriptInterface
    public void showToast(String toast) {
        Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
    } }
使用addJavascriptInterface将上述类绑定到WebView中运行的JavaScript

HTML

更多细节

WebView webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />

<script type="text/javascript">
    function showAndroidToast(toast) {
        Android.showToast(toast);
    }
</script>