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?
Thanks in advance.
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.
Are you saying you want to know what the user typed in another app? If so, I don't believe you can. In theory you can try skipping the real SMS app and using a plugin: http://plugins.cordova.io/#/package/com.jsmobile.plugins.sms
Nowadays there are ionic wrappers for cordova extensions. You can use $cordovaSMS (docs here)
module.controller('ThisCtrl', function($cordovaSms) {
document.addEventListener("deviceready", function () {
$cordovaSms
.send('phonenumber', 'SMS content', options)
.then(function() {
// Success! SMS was sent
}, function(error) {
// An error occurred
});
});
});
To see what the user is typing you can have them write the 'SMS content' inside your app. One you leave your app I don't think you can grab text from the native SMS field