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