In this article we will take a look at sending SMS using PhoneGap in a Hybrid application using Icenium. Let us create a view like the following to send SMS:
The above view can be created using the following code:
<div data-role="view" id="messageview" data-title="Send SMS">
<h1>Send Messages!</h1>
<div id='helloWorldInput'>
<label for="txtName" style="display: inline-block;">Enter Phone Number to send message:</label>
<input type="text" id="txtPhoneNumber1" value="" />
<input type="text" id="txtPhoneNumber2" value="" />
</div>
<div class="buttonArea">
<a id="submitButton" data-role="button" data-click="sayMessage" data-icon="compose">Send Message</a>
</div>
</div>
On click of the Send Message button a SMS can be sent as in the following:
function sayMessage() {
var phn1 = document.getElementById('txtPhoneNumber1').value;
var phn2 = document.getElementById('txtPhoneNumber2').value;
var phonenumbers = phn1 + "," + phn2
window.location.href = "sms:" + phonenumbers + "?body=" + "hello test message";
}
In the above code snippet we are reading two phone numbers and concatenating them with a comma. After that we use sms: to send the message. It will open a native Message application with configured phone numbers and message body.
I hope you find this article useful. Thanks for reading.