native for Dcloud. js Direct Call Android Instance Code

  • 2021-10-15 11:39:47
  • OfStack

Use native. js of Dcloud to make a direct call instance code Android version, only Android version instance due to the limitation of iOS system

The following three ways can be examples, and everyone can test that there is always one suitable for you


function call(){
 //  Import Activity , Intent Class 
 var Intent = plus.android.importClass("android.content.Intent");
 var Uri = plus.android.importClass("android.net.Uri");
 //  Get the main Activity Object 
 var main = plus.android.runtimeMainActivity();
 //  Create Intent
 var uri = Uri.parse("tel:10010"); //  You can change the phone number here 
 var call = new Intent("android.intent.action.CALL",uri);
 //  Call startActivity Method to make a phone call 
 main.startActivity( call );
 // ...
}

Instance in the plus.device.dial('1008611',false) Call false directly, and true requires the user to confirm

Or


<!DOCTYPE html>
<html>
 <head>
 <meta charset="utf-8">
 <title>Device Example</title>
 <script type="text/javascript">
// H5 plus Event handling 
function plusReady(){
}
if(window.plus){
 plusReady();
}else{
 document.addEventListener("plusready",plusReady,false);
}
function dialTest() {
 plus.device.dial( "10086", false );
}
 </script>
 </head>
 <body>
   Make a phone call <br/>
  <button onclick="dialTest()">Dial</button>
 </body>
</html>

The following is a simpler one, adding TEL to the A tag of HTML5


<a href="TEL:10086" rel="external nofollow" >HTML5 Make a phone call </a>

Attached is a detailed introduction and explanation of Native of Dcloud. API supported by js

www.dcloud.io/docs/api/index.html

To see more about native. js example code, you can see the related links on page 1


Related articles: