I am trying to send sms from a device using sms manager by adding the corodova send sms plugin .This app works fine till android6.0 device it sends the sms also but when i tried to send sms from android7.0 it shows me the following security exception.Before sending sms it asks for the permission and i have given the permission also.
Exception:
java.lang.SecurityException:
at android.os.Parcel.readException(Parcel.java:1683)
at android.os.Parcel.readException(Parcel.java:1636)
at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getGroupIdLevel1(IPhoneSubInfo.java:583)
at android.telephony.TelephonyManager.getGroupIdLevel1(TelephonyManager.java:2163)
at android.telephony.SmsMessage.hasEmsSupport(SmsMessage.java:854)
at com.android.internal.telephony.SmsMessageBase.calcUnicodeEncodingDetails(SmsMessageBase.java:409)
at com.android.internal.telephony.gsm.SmsMessage.calculateLength(SmsMessage.java:796)
at android.telephony.SmsMessage.fragmentText(SmsMessage.java:354)
at android.telephony.SmsManager.divideMessage(SmsManager.java:450)
at com.cordova.plugins.sms.Sms.send(Sms.java:143)
at com.cordova.plugins.sms.Sms.access$400(Sms.java:22)
at com.cordova.plugins.sms.Sms$1.run(Sms.java:102)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Code to send sms:
var smsdata = ' தேதி: ' + this.currentbilldate + ' பில் எண்: ' + this.save_details.vehicle_bill_no + ' எடுக்கப்பட்ட பொருட்களின் விவரங்கள்: ' + this.smselements.toString() + ', மொத்த பொருட்கள்: ' + totalcount + '';
var farmermobileno = this.entry_details.farmer_mobile_no;
this.sms.send(farmermobileno, smsdata).then((result) => {
this.commonService.presentToast('Message sent successfully');
}, (error) => {
console.log('Error in sending message', error);
this.commonService.presentToast('Message Failed');
});
Plugin Name: cordova-sms-plugin
Text sending in sms:
var smsdata = 'உங்கள் கணக்கில் அன்று 23-8-17 அட்வான்ஸ் தொகை ₹500 வழங்கப்பட்டுள்ளது.இருப்பு ₹5000';
Hope you can use below method for checking permissions.
On Android, an extra function is exposed to know whether or not you have the permission to send a SMS (Android Marshmallow permission).
var app = {
checkSMSPermission: function() {
var success = function (hasPermission) {
if (hasPermission) {
sms.send(...);
}
else {
// show a helpful message to explain why you need to require the permission to send a SMS
// read http://developer.android.com/training/permissions/requesting.html#explain for more best practices
}
};
var error = function (e) { alert('Something went wrong:' + e); };
sms.hasPermission(success, error);
}
};
You can see more details here on Git too.
Update:
var smsdata = 'உங்கள் கணக்கில் அன்று 23-8-17 அட்வான்ஸ் தொகை' + '₹500' + 'வழங்கப்பட்டுள்ளது.இருப்பு'+ '₹5000';
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