<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.androidandh5.JsCallJavaCallPhoneActivity"> <WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent"/> </RelativeLayout>
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); } } }
原文地址:https://www.cnblogs.com/znsongshu/p/9373989.html
时间: 2024-10-09 11:11:36