Android Question Send SMS

I added this function to my project:
B4X:
Sub SendMultipartTextMessage(Number As String, Message As String, SubscriptionId As Int)
    Dim r As Reflector
    r.Target = r.RunStaticMethod("android.telephony.SmsManager", "getSmsManagerForSubscriptionId", Array As Object(SubscriptionId), Array As String("java.lang.int"))
    Dim parts As Object
    parts = r.RunMethod2("divideMessage", Message, "java.lang.String")
    r.RunMethod4("sendMultipartTextMessage", _
        Array As Object(Number, Null, parts, Null, Null), _
        Array As String("java.lang.String", "java.lang.String", _
            "java.util.ArrayList", "java.util.ArrayList", "java.util.ArrayList"))
End Sub
These two permissions have also been added to the manifest. I also get them from the user with the RuntimePermissions library:
B4X:
AddPermission(android.permission.READ_PHONE_STATE)
AddPermission(android.permission.SEND_SMS)
This code works correctly and SMS is sent on Android 13, but I have a problem:
I have two SIM cards in my phone, but when this code is executed, the message is sent only with SIM card 1, even if the phone SMS is set to SIM 2 by default.
B4X:
SendMultipartTextMessage("09111111111","test2",2)
How can I solve this problem so that I can send messages with the second SIM card as well?

Another question! How can I define a listener to find out that the SMS was really sent and reached the user and that it was not affected by reasons such as lack of antenna or lack of SIM card validity?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top