1.androidandjsinterface.java
Class Androidandjsinterface {/** * This method will be called by JS for loading data */@JavascriptInterfacepublic void showcontacts () {// The following code recommends invoking string json = "{\" name\ ": \" "" "," phone\ ": \" 18600012345\ "}]" in a child thread, and/or invoke the method in JS Webview.loadurl ("javascript : Show (' + JSON + ') ');} /** * Call * @param phone */@JavascriptInterfacepublic void call (String phone) {Intent Intent = new Intent (intent.action_c All, Uri.parse ("Tel:" + phone)); if (Activitycompat.checkselfpermission (Jscalljavacallphoneactivity.this, Manifest.permission.CALL_PHONE)! = packagemanager.permission_granted) {return;} StartActivity (intent);}}
2.deml.html
<script type= "Text/javascript" >function Show (Jsondata) { var jsonobjs = eval (jsondata); var table = document.getElementById ("persontable"); for (var y=0; y<jsonobjs.length; y++) {var tr = Table.insertrow ( Table.rows.length); var td1 = Tr.insertcell (0), var td2 = 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>.............<table border= "0" width= "100%" id= "persontable" cellspacing= "0" ><tr><td Width= "30%" > Name </td><td align= "center" > Phone </td></tr></table>
H5 calls Android phone call