H5 calls Android and h5android calls
1. AndroidAndJSInterface. java
Class AndroidAndJSInterface {/*** this method will be called by js for loading data */@ JavascriptInterfacepublic void showcontacts () {// the following code suggests calling String json = "[{\" name \ ": \" AFU \ ", \" phone \ "in the Child thread \": \ "18600012345 \"}] "; // call the webView method in JS. loadUrl ("javascript: show ('" + json + "')");}/*** call ** @ param phone */@ JavascriptInterfacepublic void call (String phone) {Intent intent = new Intent (Intent. ACTION_CALL, 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 number </td> </tr> </table>