H5 calls Android phone call

Source: Internet
Author: User

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

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.