如何使用JavaScript在Android上运行本机视频播放器



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

您可以使用

WebView。下面是显示网页中的 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();
    } }

将上述类绑定到运行WebView的 JavaScript 中,

并带有 addJavascriptInterface()
WebView webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");

.HTML

<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />
<script type="text/javascript">
    function showAndroidToast(toast) {
        Android.showToast(toast);
    }
</script>

更多细节在这里

最新更新