I'm building an Ionic/Cordova app. From my application, user can click on a phone number in order to send SMS. When click on that number, native SMS app will open and then user can type his/her own SMS and send the SMS. Is there any way, from my app I can get the SMS content?
As you are using ionic/cordova, a SMS plugin is required to do such work.
Besides jsmobile SMS plugin, there is another one with more APIs: http://plugins.cordova.io/#/package/com.rjfun.cordova.sms
As mentioned in the description:
sendSMS(address(s), text, successCallback, failureCallback);
listSMS(filter, successCallback, failureCallback);
deleteSMS(filter, successCallback, failureCallback);
startWatch(successCallback, failureCallback);
stopWatch(successCallback, failureCallback);
enableIntercept(on_off, successCallback, failureCallback);
restoreSMS(msg_or_msgs, successCallback, failureCallback);
Events
'onSMSArrive'
You can get the SMS content in either of the following ways:
Or,
BTW, the plugin works for Android only, FYI.
There is cordova-plugin-sms option, as @MikeX suggested, but notice that its license is not free use.
So I chose using Phonegap-SMS-reception-plugin, which is MIT license.
and then it just
var smsInboxPlugin = cordova.require('cordova/plugin/smsinboxplugin');
smsInboxPlugin.startReception (function(msg) {
alert(msg);
stopReadingSMS(smsInboxPlugin);
}, function() {
alert("Error while receiving messages");
stopReadingSMS(smsInboxPlugin);
});
function stopReadingSMS(smsInboxPlugin) {
smsInboxPlugin.stopReception (function() {
console.log("Correctly stopped SMS receiver");
}, function() {
console.log("Error while stopping the SMS receiver");
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With