We can send messages to our desired phone number using the cordovaSMS plugin.

Start Ionic project using.


ionic start sms blank

Then go to SMS folder.


cd sms

Then add cordovaSMS plugin.


cordova plugin add https://github.com/cordova-sms/cordova-sms-plugin.git

To execute the above command use Git Bash only.

Download ngCordova using

https://github.com/driftyco/ng-cordova/archive/master.zip

Include ngCordova js file in index.html.


<script type="text/javascript" src="js/ng-cordova.min.js" ></script>

Add controller.


<body ng-app="starter" ng-controller="smsctrl" >

Add ngCordova to app.js.


angular.module('starter', ['ionic','ngCordova'])

Now we going to send SMS using GSM carrier when the user presses send button.

Add button inside ion-content tag.


<button class="button button-positive" ng-click="sendsms()" >All Contacts</button>

Create sendsms function inside your controller.


controller('smsctrl',function($scope,$ionicPlatform,$cordovaSms){

$scope.sendsms=function()

{

document.addEventListener("deviceready", function () {

//CONFIGURATION

    var options = {

    replaceLineBreaks: false, // true to replace \n by a new line, false by default

    android: {

    //intent: 'INTENT' // send SMS with the native android SMS messaging

    intent: '' // send SMS without open any other app

    }

    };

    $cordovaSms

    .send('7200615373', 'SMS content', options)

    .then(function() {

    // Success! SMS was sent

    alert("sent");

    }, function(error) {

    // An error occurred

    alert("can't sent");

    });

});

}

})

That’s all. To generate apk.


ionic platform add android

ionic build android

Note: If you don't have SMS pack, it will cost you.

 

Tested Device

Samsung J7 Android Lolipop.

Source

APK