In this post we will take a look on sending SMS using PhoneGap in a Hybrid application creating using Icenium. Let us create a view like following to send SMS,
Above view can be created using following code snippet,
<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> <a id="submitButton" data-role="button" data-click="sayMessage" data-icon="compose">Send Message</a> </div> </div>
On click of Send Message button a SMS can be send as 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 above code snippet we are reading two phone numbers and concat them with comma. After that using sms: to send the message. It will open native Message application with configured phone numbers and message body.
I hope you find this post useful. Thanks for reading.