SMS
The SMS feature enables your mobile application to send and receive SMS.
Supported Platforms
This feature is supported in the following platforms:
- iOS (send SMS only)
- Android
Installation
To install the Send SMS plugin, execute the following command in your Cordova project directory:
cordova plugin add cordova-sms-plugin
To install the Receive SMS plugin, execute the following command in your Cordova project directory:
cordova plugin add cordova-plugin-sms
Usage
Send SMS
The following code snippet sends a “Hello from Canvas Technology” message to a specified mobile number when the "Send" button is clicked:
/* The following function sends a message when "SEND SMS" button is clicked. * Here, CFEC.CLICK is the Canvas event that can be used to capture the button clicked action. * SEND is the form item ID for the "SEND SMS" button. */ this.fm.registerHandler(CFEC.CLICK, "SEND", function (fm, event, fieldName, value) { var params = { number: "9566026960", message: "Hello from Canvas Technology", options: { replaceLineBreaks: false, android: { intent: 'INTENT' } } }; canvas.env.comm.SMS.sendSMS(params, successSMS, errorSMS); }); // The following function displays the message after a SMS is successfully sent. function successSMS(status) { showAlert("SMS is sent successfully." + status); } // The following function displays the message when a SMS is not sent. function errorSMS(err) { showAlert("Unable to send SMS."); }
Receive SMS
The following code snippet is for receiving SMS:
/* The following function receives SMS messages when "RECEIVE SMS" button is clicked. * Here, CFEC.CLICK is the Canvas event that can be used to capture the button clicked action. * RECEIVE is the form item ID for the "RECEIVE SMS" button. */ this.fm.registerHandler(CFEC.CLICK, "RECEIVE", function (fm, event, fieldName, value) { canvas.env.comm.SMS.receiveSMS(successrSMS, errorrSMS); }); // The following function displays the message after a SMS is successfully received. function successrSMS(event) { showAlert("Received SMS successfully." + event.data.body); } // The following function displays the message when a SMS is not received. function errorrSMS(err) { showAlert("Unable to receive SMS."); }