Android Question Send sms with sim2

RezaFaearhi

New Member
Hello, I use this code to send SMS with SIM card 2
SendSms java boolean:
#If Java

public boolean sendSms(String phoneNumber, String text, int sim) throws Exception {
    try {
      SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(sim);
      ArrayList<String> parts = smsManager.divideMessage(text);
      smsManager.sendMultipartTextMessage(phoneNumber, null, parts, null, null);
      return true;
    } catch (Exception e) {
       return false;
    }
}

#End If

B4a:
rp.CheckAndRequest("android.permission.SEND_SMS")
rp.CheckAndRequest("android.permission.READ_PHONE_STATE")
    
Dim jo As JavaObject
jo.InitializeContext
jo.RunMethod("sendSms",Array("0999999999","test",1))
ManifestCode:
AddPermission(android.permission.READ_PHONE_STATE)

AddPermission(android.permission.SEND_SMS)


This code works correctly in some Xshaimi devices, but it gives the following error in Samsung :
Java.lang.RuntimeEcxeption : Object
Shold First be initialazed ( Exception)

even from
SendLargeSms:
Sub SendLargeSms(Number As String, Message As String, SubscriptionId As Int)
    Dim r As Reflector
    r.Target = r.RunStaticMethod("android.telephony.SmsManager", "getSmsManagerForSubscriptionId", Array(SubscriptionId), Null)
    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
I used But I received the following error:
Java.lang.NoSuchMethodEcxeption
android.telephony.SmsManager.getSmsManagerForSubscriptionId[]

Will Earl help me?
 

RezaFaearhi

New Member
The problem was solved

SendMultipartTextMessage:
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
 
Upvote 0
Top