H5 calls Android and h5android calls

Source: Internet
Author: User

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>

 

Related Article

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.