assuming your receiver looks more or less like this:
Sub Process_Globals
Private jo,smanager,sinfo As JavaObject
End Sub
'Called when an intent is received.
'Do not assume that anything else, including the starter service, has run before this method.
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
jo.initializecontext
Log("Receiver started")
Log( "started by: " & StartingIntent.Action)
Log("extras: " & StartingIntent.ExtrasToString)
Dim subid As Int = StartingIntent.GetExtra("subscription")
smanager = jo.RunMethod("getSystemService",Array As String ("telephony_subscription_service"))
sinfo = smanager.RunMethod("getActiveSubscriptionInfo",Array(subid))
Log("your carrier: " & sinfo.runmethod("getCarrierName",Null))
End Sub
you can derive the carrier that handled the sms. i tried it on android 12 and 14.
This is how I process the SMS. The Sub ParseSmsIntent is called from Service_Start
Sub Service_Start (StartingIntent As Intent)
Log("MySMSReader Service Started")
If StartingIntent.Action = "android.provider.Telephony.SMS_RECEIVED" Then
Dim messages() As Message
messages = ParseSmsIntent(StartingIntent)
End If
Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub
Sub ParseSmsIntent (in As Intent) As Message()
Log("Inside ParseSmsIntent")
Dim messages() As Message
If in.HasExtra("pdus") = False Then Return messages
Dim pdus() As Object
Dim r As Reflector
pdus = in.GetExtra("pdus")
If pdus.Length > 0 Then
Dim messages(pdus.Length) As Message
For i = 0 To pdus.Length - 1
r.Target = r.RunStaticMethod("android.telephony.SmsMessage", "createFromPdu", _
Array As Object(pdus(i)), Array As String("[B"))
messages(i).Body = r.RunMethod("getMessageBody")
messages(i).Address = r.RunMethod("getOriginatingAddress")
messages(i).SimIndex = in.GetExtra("android.telephony.extra.SLOT_INDEX") 'Here I get the SIM slot number
Log("Sim Index is" & messages(i).SimIndex)
Next
End If
Return messages
End Sub
This is the result of in.ExtrasToString
Intent Extras = Bundle[{android.telephony.extra.SUBSCRIPTION_INDEX=2, messageId=-3135271800800894780, format=3gpp, android.telephony.extra.SLOT_INDEX=0, pdus=[[7, -111, 25, -119, 4, 16, -111, 6, 4, 12, -111, 25, -119, 89, -112, 96, 32, 0, 0, 66, 32, 2, 113, 18, 33, 34, 9, -62, -80, -72, 14, -54, -27, 114, 57]], phone=0, subscription=2}]
I tried your code but I get a runtime error at the line
sinfo = smanager.RunMethod("getActiveSubscriptionInfo",Array(subid))
mysmsreceiver_parsesmsintent (java line: 232)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at smsrdr.kkk.mysmsreceiver._parsesmsintent(mysmsreceiver.java:232)
at smsrdr.kkk.mysmsreceiver$ResumableSub_Service_Start.resume(mysmsreceiver.java:324)
at smsrdr.kkk.mysmsreceiver._service_start(mysmsreceiver.java:259)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at smsrdr.kkk.mysmsreceiver.handleStart(mysmsreceiver.java:100)
at smsrdr.kkk.mysmsreceiver.access$000(mysmsreceiver.java:8)
at smsrdr.kkk.mysmsreceiver$2.run(mysmsreceiver.java:80)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: java.lang.SecurityException: getActiveSubscriptionInfo
at android.os.Parcel.createExceptionOrNull(Parcel.java:2438)
at android.os.Parcel.createException(Parcel.java:2422)
at android.os.Parcel.readException(Parcel.java:2405)
at android.os.Parcel.readException(Parcel.java:2347)
at com.android.internal.telephony.ISub$Stub$Proxy.getActiveSubscriptionInfo(ISub.java:1376)
at android.telephony.SubscriptionManager.getActiveSubscriptionInfo(SubscriptionManager.java:1411)
... 19 more