0

I am working on an android application in which I want to send Sms with SmsManager. Everything is working fine if I use a Single sim phone but when I use a dual sim phone I want to ask the user "from which sim card you want to send Sms" Please help me to archive that. And my device does not have the option to set the default sim card to send SMS so how can I set that programmatically.

here is my code-

private void MyMessage() {
        String mobileNumber1 = "99XXXXXXXX";
        String mobileNumber2 = "99XXXXXXXX";
        String myMsg = "Testing Messages";

            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(mobileNumber1, null, myMsg, null, null);
            smsManager.sendTextMessage(mobileNumber2, null, myMsg, null, null);
            Toast.makeText(this, "Message Sent", Toast.LENGTH_SHORT).show();

    }
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Akshay Rajput
  • 250
  • 4
  • 11
  • > Manages SMS operations such as sending data, text, and pdu SMS > messages. Get this object by calling the static method getDefault(). > To create an instance of SmsManager associated with a specific > subscription ID, call getSmsManagerForSubscriptionId(int). This is > typically used for devices that support multiple active subscriptions > at once. This is the first line in explaining about the sms manager. Try using this method `getSmsManagerForSubscriptionId(int)` instead of `getDefault()` – Lena Bru Jun 10 '20 at 15:07
  • 1
    I already lookup to this post but I didn't understand can you please explain which of the answer is correct and how that works. thanks in advance – Akshay Rajput Jun 10 '20 at 15:13
  • You also need to use the subscription manager, that and this method together will give you the correct sms manager for the user's choice of a sim card – Lena Bru Jun 10 '20 at 15:21
  • 1
    ok thanks again for your time – Akshay Rajput Jun 10 '20 at 16:11

0 Answers0