Java and JS Intermodulation calls

Source: Internet
Author: User

<!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML>    <Head>        <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">        <title>Insert Title here</title>        <Scripttype= "Text/javascript">            functionShow (jsondata) {varJsonobjs=eval (jsondata); varTable=document.getElementById ("persontable");  for(vary=0; y<jsonobjs.length; y++){                        varTR=Table.insertrow (table.rows.length); varTD1=Tr.insertcell (0); varTD2=Tr.insertcell (1); Td2.align= "Center"; Td1.innerhtml=Jsonobjs[y].name; Td2.innerhtml= "<a href= ' Javascript:Android.call (\ ""+Jsonobjs[y].phone+ "\ ") ' >"+Jsonobjs[y].phone+ "</a>"; }            }                    </Script>    </Head>    <Bodyonload= "javascript:Android.showcontacts ()">    <DivAlign= "Left">Welcome to visit</Div>    <P><imgsrc= "Http://atguigu.com/images/logo.gif"></P>    <TableBorder= "0"width= "100%"ID= "Persontable"cellspacing= "0">            <TR>                <TDwidth= "30%">Name</TD>                <TDAlign= "Center">Phone</TD>            </TR>        </Table>            </Body></HTML>
 Public classJscalljavacallphoneactivityextendsActivity {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 Local Resources//Webview.loadurl ("http://atguigu.com/teacher.shtml");Webview.loadurl ("file:///android_asset/JsCallJavaCallPhone.html");//Webview.loadurl ("http://10.0.2.2: 8080/assets/jscalljavacallphone.html ");    }    classAndroidandjsinterface {/*** This method will be called by JS to load the data*/@JavascriptInterface Public voidshowcontacts () {//The following code recommends calling a child thread in theString json = "[{\" name\ ": \" Ford \ ", \" phone\ ": \" 18600012345\ "}]"; //invoking the method in JSWebview.loadurl ("Javascript:show ('" + JSON + "')"); }        /*** Call *@paramPhone*/@JavascriptInterface Public voidCall (String phone) {Intent Intent=NewIntent (Intent.action_call, Uri.parse ("Tel:" +phone)); if(Activitycompat.checkselfpermission (jscalljavacallphoneactivity. This, Manifest.permission.CALL_PHONE)! =packagemanager.permission_granted) {                return;        } startactivity (Intent); }    }}

Java and JS Intermodulation calls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.