SMS and phone calls for ionic projects

Source: Internet
Author: User

Original address:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/ionic-sms-and-call/

A recent ionic project needs to implement texting and calling, summarizing the problems encountered and how to implement them.

1. About the phone

In the HTML can be very convenient to make a call first in the config. xml to add:

<access origin= "tel:*" launch-external= "yes"/>

Then write this in HTML :

<a href= "tel:10086" > Call 10086</a>

But I wanted to get a click on the phone, so I made a change:

In HTML:

<button ng-click= "Callfriend ($event, friend)" ></button>

JS in:

$scope. callfriend = function ($event, friend) {window.open (' Tel: ' + friend.   PhoneNumber); Get the call time var time=new date ();}

Sometimes do not want to automatically identify the phone, in order to prevent phone recognition, you can add this sentence in the header file:

<meta name= "format-detection" content= "Telephone=no" >

2. About texting, is the plugin used by Ng-cordova $cordovasms:

Add the plugin First:

Cordova Plugin Add Https://github.com/cordova-sms/cordova-sms-plugin.git

remember the corresponding to be in the app . js dependent on Ng-cordova in the controller that sends the SMS $cordovaSms .

I realized that clicking the text button will pop up a popup:

To add a click event to the HTML:

<button ng-click= "Opensendmessage (phonenumber)" ></button>

Write the function that sends the SMS in the controller:

Open the popup$scope.opensendmessage = function  (PhoneNumber) that sent the SMS  {  $ RootScope.sendMessagePopup.show (PhoneNumber)     .then (function  (Result)  {       return result;    });}; $scope .sms = {  number:  ' 10086 ',  message:  ' Happy Birthday '};var options  = {  replaceLineBreaks: false, // true to replace \n  by a new line, false by default  android: {     intent:  '  // send SMS with the native android SMS  messaging    //intent:  '  // send sms without open any  other app    //intent:  ' Intent '  // send sms inside  a default SMS app  }}; $scope .sendsms = function  ()  {   $cordovaSms. Send (' 10086 ',  ' Happy Birthday ',  options)      .then (function  ()  {      alert (' Send SMS Success ');     }, function  (Error)  {      alert (' Send SMS failed ');     });};


SMS and phone calls for ionic projects

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.