<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns: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"> <WebViewAndroid:id= "@+id/webview"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"/></Relativelayout>
Public classJscalljavavideoactivityextendsActivity {PrivateWebView WebView; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_js_call_java_video); WebView=(WebView) Findviewbyid (R.id.webview); WebSettings websettings=webview.getsettings (); //set support JavaScript footstep languageWebsettings.setjavascriptenabled (true); //Double-click Support-provided the page is supported for display//Websettings.setusewideviewport (TRUE); //Support for zoom buttons-provided the page is supported for displayWebsettings.setbuiltinzoomcontrols (true); //set client-do not jump to the default browserWebview.setwebviewclient (Newwebviewclient ()); //Set Support JS call JavaWebview.addjavascriptinterface (NewAndroidandjsinterface (), "Android"); //Load network resources//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 "); } classAndroidandjsinterface {/*** This method will be called by JS *@paramID *@paramVideourl *@paramTile*/@JavascriptInterface Public voidPlayVideo (intid,string videourl,string Tile) { //Tune up all players in the systemIntent Intent =NewIntent (); Intent.setdataandtype (Uri.parse (videourl),"video/*"); StartActivity (Intent); } }}
System player for Java and JS Mutual tune