This article is for Ionic V1 for current version of ionic Please Read this article working on Android visit Ionic 3 Cordova Read SMS plugin .
In Ionic Framework to read SMS messages from device you can use cordova plugin.
So, first of all install cordova SMS plugin in your application.
cordova plugin add cordova-plugin-sms
You can use these following methods.
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);
setOptions(options, successCallback, failureCallback);
To Read List of SMS:-
angular.module('starter', ['ionic','ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
var filter = {
box : 'inbox', // 'inbox' (default), 'sent', 'draft'
indexFrom : 0, // start from index 0
maxCount : 10, // count of SMS to return each time
};
if(SMS) SMS.listSMS(filter, function(data){
console.log(data);
},
function(err){
console.log('error list sms: ' + err);
});
});
})
Make sure always use method in Ionic Framework inside the $ionicPlatform.ready(function() {}; else it will not work.
To Read SMS on Arrive:-
First startWatch() watching for new messages the and when new message arrive onSMSArrive event is triggered. To read OTP SMS you can use this feature.
angular.module('starter', ['ionic','ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(SMS) SMS.startWatch(function(){
console.log('watching started');
}, function(){
console.log('failed to start watching');
});
document.addEventListener('onSMSArrive', function(e){
var sms = e.data;
console.log(sms);
});
});
})
To Send SMS-
angular.module('starter', ['ionic','ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(SMS) SMS.sendSMS("+9112345","msg",function(){
console.log("Sent");
}, function(e){
console.log("Error occurs")
});
});
})
hi, how to use enableIntercept?
ReplyDeleteI tried, but the sms is still go native app
var interceptEnabled = true;
ReplyDeleteif(SMS) SMS.enableIntercept(interceptEnabled, function(){
console.log("Enabled");
}, function(e){
console.log("error");
});
for Enable or Disable intercept set interceptEnabled value true or false.
I tried, but the sms is still go native app. ( on android 6.0.1 )
DeleteThis comment has been removed by the author.
ReplyDeletethe plugin is working fine with android but nothing is happening with ios app
ReplyDeleteIOS not allow to read SMS.
DeletePlease help me I am using redmi prime 3s (android 6.0.1) but Not working sms receive
ReplyDeleteYou need to allow permission for read sms read this article for current version of ionic http://www.programmingworldtech.com/2017/09/ionic-3-cordova-read-sms-plugin.html
DeleteError in var sms = e.data;
ReplyDeletemake sure call the function inside the Platform ready.
DeleteI have same issue. It says "Property 'data' does not exist on type 'Event'" but it is there
DeleteIf i start ionic project like "ionic start project_name blank' and write code into file 'home.ts' how i should to import variables angular and SMS?
ReplyDeleteHii Pomah, this code sample is for Ionic v1. For current version of ionic you can add ionic native sms plug-in. See here https://ionicframework.com/docs/native/sms/
DeleteBut there read sms method doesnt exist
Deletehttp://www.programmingworldtech.com/2017/09/ionic-3-cordova-read-sms-plugin.html Read this article working for android
DeleteHow to use deleteSMS? it doesn't delete messages on inbox of my phone
ReplyDeleteHi, To delete SMS first you need to enable android WRITE_SMS permission.
DeleteTo enable WRITE_SMS permission first add cordova-plugin-android-permissions.
Thank You.
Thank you for your reply. I have checked my permission using the said plugin. I do have permission on WRITE_SMS. It is also said in my log that the delete is successful. However it doesn't delete anything on my inbox.
ReplyDeleteHi, DAR
DeleteThis will help you https://github.com/floatinghotpot/cordova-plugin-sms/issues/67
delete function has been removed for android 5.0+ based on the issue. Anyways, Thanks for your help Nandan. :)
DeleteHi! I have some problems with this, error: SMS is not defined.
ReplyDeletengCordova is already implemented. Cordova 6.3.1. Also the code is been executed in $ionicPlatform.
Any ideas?
Thank you!!
Based on current growth figures, SMS Messaging will become an ever increasingly important component in future marketing communications.
ReplyDeletepadisoft.org
I want more and more articles and blogs please post soon such informative information.
ReplyDeletetutorial on c++
TreasureBox is operated by a group of young, passionate, and ambitious people that are working diligently towards the same goal - make your every dollar count, as we believe you deserve something better.
ReplyDeletegazebo
pop up gazebo
sofa bed