public class JsCallJavaVideoActivity extends Activity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_js_call_java_video);
webView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
//设置支持javaScript脚步语言
webSettings.setJavaScriptEnabled(true);
//支持双击-前提是页面要支持才显示
// webSettings.setUseWideViewPort(true);
//支持缩放按钮-前提是页面要支持才显示
webSettings.setBuiltInZoomControls(true);
//设置客户端-不跳转到默认浏览器中
webView.setWebViewClient(new WebViewClient());
//设置支持js调用java
webView.addJavascriptInterface(new AndroidAndJSInterface(),"android");
//加载网络资源
// webView.loadUrl("http://atguigu.com/teacher.shtml");
webView.loadUrl("file:///android_asset/RealNetJSCallJavaActivity.htm");
// webView.loadUrl("http://10.0.2.2:8080/assets/RealNetJSCallJavaActivity.htm");
}
class AndroidAndJSInterface {
/**
* 该方法将被js调用
* @param id
* @param videoUrl
* @param tile
*/
@JavascriptInterface
public void playVideo(int id,String videoUrl,String tile){
//调起系统所有播放器
Intent intent = new Intent();
intent.setDataAndType(Uri.parse(videoUrl),"video/*");
startActivity(intent);
}