Example

 
This is what our application looks like:
 

HTML

Application main page.
 
<!DOCTYPE html>
<html ng-app="starter">
  <head>
    <meta charset="utf-8">
	<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src  'self' 'unsafe-inline' *">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
	<script src="js/ng-cordova.min.js"></script>		
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
  </head>
  <body ng-controller="SMSController">

    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">SMS Example</h1>
      </ion-header-bar>
      <ion-content>
        <div class="list">
          <label class="item item-input">
            <span class="input-label">Number</span>
            <input type="text" ng-model="sms.number">
          </label>
          <label class="item item-input item-floating-label">
            <span class="input-label">Message</span>
            <input type="text" placeholder="Message" ng-model="sms.message">
          </label>
          <button class="button button-full button-positive" ng-click="sendSMS()">
            Send SMS
          </button>
        </div>	  
      </ion-content>
    </ion-pane>
  </body>
</html>
 

JavaScript

Application JavaScript file.
 
// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
var app = angular.module('starter', ['ionic', 'ngCordova'])

app.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if (window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
});

app.controller('SMSController', function($scope, $cordovaSms) {
  $scope.sms = {
    number: '0959052082',
    message: 'This is some dummy text'
  };

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

    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('0959052082', 'This is some dummy text', options)
        .then(function() {
          alert('Success');
          // Success! SMS was sent
        }, function(error) {
          alert('Error');
          // An error occurred
        });
    }
  });
});
 

Deployment

 
Next step, we need to build our application:
 
ionic build android
 
Be careful here, this step may break if you’re behind a firewall. The first execution will take a long time, so be patient.
 
When this step ends, look at the output log, last two lines should look something like this:
 
Built the following apk(s):
    D:\Development\IonicSendSMSDemo\platforms\android\build\outputs\apk\android-debug.apk
 
We’ll use the last line location to deploy our application. Make sure your smartphone is prepared to accept an incoming application. In case of Android platform, you must enable Developer Options and USB Debugging.
 
Do this:
 
adb install -r platforms\android\build\outputs\apk\android-debug.apk
 
or you can do this:
 
ionic run android -l -c -s
 

Who Am I?

Between working as a senior Java developer in one of the largest insurance companies in the world and traveling, in my free time, I work as a professional mobile development adviser. I'm also a major jQuery Mobile supporter back at StackOverflow and a forum moderator at the official Ionic Framework forum.