可以从网页浏览器点击按钮或链接启动android原生播放器吗?我不想在浏览器中使用html5视频标签来播放它。
发布于 2013-12-26 14:32:51
为此,您可以使用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();
} }使用addJavascriptInterface()将上述类绑定到在WebView中运行的JavaScript
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>更多详细信息here
https://stackoverflow.com/questions/20779782
复制相似问题