androidsmsmanager

Android: Attempting to send an SMS via SmsManager redirects the message to the default app with no address


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

Solution

  • 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 (i.e the SMS is being sent by my app).