As per the tile, I use the following code:
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(sms_receiver, null, sms_content, null, null);
No errors and no exceptions. While the above seems to work fine in android studio's emulator that I use, when I install my app on my device, again no errors or crashes, but the message goes to my default SMS app as a draft with no recipient.
After searching I, was lead to believe that the fact my mobile phone is dual sim (although I have only one inserted in my device) is the problem and can be addressed by using the "scAddress" argument.
I'm still not sure if the above is right and I couldn't find a way to get the scAddress programmatically.
If it is at all relevant, the model I have is a Xiaomi Redmi Note 6 Pro and the API of the android app:
minSdkVersion 25
targetSdkVersion 29
I assume you've tried setting the service center address in the second argument of smsManager.sendTextMessage?
Looks like it should be a phone number: Look here for more info:
The problem was indeed that the
SmsManager smsManager = SmsManager.getDefault();
wasn't getting the active sim slot. I used the snippet found in this answer: Android: How to send sms with particular SIM in dual sim mobiles?
Now the app needs READ_PHONE_STATE permission, which I would prefer wasn't the case, but it works as expected (ie the SMS is being sent by my app).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.