如何使用javascript在android上运行本机视频播放器?
是否可以从网络浏览器点击按钮或链接启动android本机播放器? 我不想在网络浏览器中使用html5视频标签来播放它 您可以使用WebView进行此操作。下面是一个代码示例,用于显示来自web页面的toast如何使用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) {
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>