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 HTML, it is convenient to make a call to add in config:
<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 to rely on the Ng-cordova in the app. js to rely on $cordovaSms in the controller that sends the SMS .
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) {$rootScope. Sendmessagepopup.show (PhoneNumber) of the sending SMS. Then ( function (Result) {return result; });}; $scope. SMS = {number: ' 10086 ', message: ' Happy birthday '};var options = {replacelinebreaks:false,//true to replace \ n by a n EW line, False by default Android: {intent: "//Send SMS with the native Android SMS Messaging//intent: '//S End SMS without open any other app//intent: ' Intent '//Send SMS inside a default SMS app}}; $scope. sendsms = Functio N () {$cordovaSms. Send (' 10086 ', ' Happy Birthday ', options). Then (function () {alert (' Send SMS successfully '); }, function (Error) {alert (' Send SMS failed '); });};
SMS and phone calls for ionic projects