Android Question Error sending SMS

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi to Everybody

I have a strange situation. The attached project works perfectly on a Motorola G54. I send and receive SMS. I have moved the same SIM on a tablet and run same App. I get the error :

java.lang.SecurityException: getCarrierConfig

I attach the log and the project.

Thanks in advance for any hint.
 

Attachments

  • logSendSms.txt
    2.1 KB · Views: 13
  • SMStest.zip
    11 KB · Views: 9

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
I have deeply investigated the problem and it seems to have no solution. My conclusion is that, much probably, there is no compatibility between the SIM and the vendor Android version on this particular issue. As a matter of fact, even a Tablet with Android 7 works, so it is not a problem related to Android 13. Paradoxically, the default Phone App sends and receives the messages on this Tablet Therefore what is blocked is only the possibility, for not default Apps, to manage SMS (it seems not to get the Carrier). To confirm this weird aspect, if I display the Mobile data of the SIM, it shows that it is not enabled to manage calls and messages (without any possibility to change this: the options are grayed). But default Phone App works, as I said. Resuming, on this Android 13 Tablet (Fossibot, to name it), while default App for Messages works, an App made with B4A doesn't. Same App, same SIM works on very old Samsung Galaxy s10 (android 7) and on Phone Motorola Android 14). Thanks for reading.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
What is the result to rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)?
add the permission to manifest
B4X:
AddPermission(android.permission.READ_PHONE_STATE)
and add the code to Main
B4X:
    rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    Log(Result)
 
Last edited:
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
No result. Nothing changes. I added the permission either in Manifest or in the Code. After this I had a long chat with chatGpt and did several trials, with all the variants. Btw yours was one of chatGpt suggestions. What is weird is that the default App works, even when called by B4A as an Intent. But no way to get a result with Send. Here is the updated code, with my trials, suggested by chatGPT. Maybe a little "messy", but it should be clear. Comments are in italian, sorry.
B4X:
#Region  Project Attributes
    #ApplicationLabel: TestSMS
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region


Sub Process_Globals
    Dim MySms As PhoneSms
    Dim rp As RuntimePermissions
    Dim PE As PhoneEvents
    Type Message (Address As String, Body As String)
End Sub

Sub Globals
    Private SEND As Button
    Private Command As EditText
    Private Number As EditText
    Private Delivered As Boolean
    Private lblLat As EditText
    Private lblLong As EditText
    Private lblRisultato As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("SMSRELAY")
    Activity.Title = "SMS RELAY CONTROL #1"
   
    rp.CheckAndRequest(rp.PERMISSION_SEND_SMS)
    rp.CheckAndRequest(rp.PERMISSION_RECEIVE_SMS)
    rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)

    Number.Text="xxxxxxx"
    Command.Text="TEST"
   
    PE.Initialize("PE")
   
End Sub

Sub SEND_Click
    Delivered=False
   
    SEND_Click_1
   
    Log("After SEND_Click")
   
End Sub

Sub SEND_Click_1
    Dim msg As String
    Dim Num As String
   
    msg = Command.Text
    Num=Number.Text.Trim
   
#if INTENT
    Dim smsIntent As Intent
    Dim numeroDestinatario As String = Number.Text ' Numero di telefono
    Dim messaggio As String = "where"

    smsIntent.Initialize(smsIntent.ACTION_VIEW, "sms:" & numeroDestinatario)
    smsIntent.PutExtra("sms_body", messaggio) ' Inserisce il testo del messaggio
    StartActivity(smsIntent)
#end if
    'Dim p As Phone
    'Log(p.GetDataState) ' this asnwers "Connected"
    MySms.Send(Num, msg)' True, True)
#if xxx
    Try
      '  Dim numeroDestinatario As String = "1234567890" ' Numero del destinatario
       ' Dim testoMessaggio As String = "Testo del messaggio" ' Messaggio da inviare
       
        ' Creazione dell'oggetto SmsManager
        Dim sm As JavaObject
        sm.InitializeStatic("android.telephony.SmsManager")
       
        ' Ottenimento dell'istanza predefinita di SmsManager
        Dim smsManager As JavaObject = sm.RunMethod("getDefault", Null)
       
        ' Invio del messaggio
        smsManager.RunMethod("sendTextMessage", Array(Num, Null, msg, Null, Null))
       
        Log("SMS inviato con successo a: " & Num)
    Catch
        Dim ex As JavaObject = LastException
        Log("Errore durante l'invio dell'SMS: " & LastException)
        Log("Causa originale: " & ex.RunMethod("getCause", Null)) ' Mostra la causa sottostante
    End Try
#end if
End Sub

Private Sub PE_SmsDelivered (PhoneNumber As String, Intent As Intent)
   Log("Delivered")
   Delivered=True
    lblRisultato.Text="Mensagem enviada"
End Sub

Private Sub PE_SmsSentStatus (Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent)
    Log("SMS SENTSTATUS" & Success)
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub


Sub RiceveSms(Cmd As String)
    'ToastMessageShow("Recv:" & Cmd,True)
    Log("Riceve " & Cmd)
    Dim su As StringUtils
    lblRisultato.Text=su.DecodeUrl(Cmd,"UTF8")
   
End Sub
 

Attachments

  • SMStest.zip
    11.6 KB · Views: 9
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
No result. Nothing changes. I added the permission either in Manifest or in the Code. After this I had a long chat with chatGpt and did several trials, with all the variants. Btw yours was one of chatGpt suggestions. What is weird is that the default App works, even when called by B4A as an Intent. But no way to get a result with Send. Here is the updated code, with my trials, suggested by chatGPT. Maybe a little "messy", but it should be clear. Comments are in italian, sorry.
B4X:
#Region  Project Attributes
    #ApplicationLabel: TestSMS
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region


Sub Process_Globals
    Dim MySms As PhoneSms
    Dim rp As RuntimePermissions
    Dim PE As PhoneEvents
    Type Message (Address As String, Body As String)
End Sub

Sub Globals
    Private SEND As Button
    Private Command As EditText
    Private Number As EditText
    Private Delivered As Boolean
    Private lblLat As EditText
    Private lblLong As EditText
    Private lblRisultato As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("SMSRELAY")
    Activity.Title = "SMS RELAY CONTROL #1"
   
    rp.CheckAndRequest(rp.PERMISSION_SEND_SMS)
    rp.CheckAndRequest(rp.PERMISSION_RECEIVE_SMS)
    rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)

    Number.Text="xxxxxxx"
    Command.Text="TEST"
   
    PE.Initialize("PE")
   
End Sub

Sub SEND_Click
    Delivered=False
   
    SEND_Click_1
   
    Log("After SEND_Click")
   
End Sub

Sub SEND_Click_1
    Dim msg As String
    Dim Num As String
   
    msg = Command.Text
    Num=Number.Text.Trim
   
#if INTENT
    Dim smsIntent As Intent
    Dim numeroDestinatario As String = Number.Text ' Numero di telefono
    Dim messaggio As String = "where"

    smsIntent.Initialize(smsIntent.ACTION_VIEW, "sms:" & numeroDestinatario)
    smsIntent.PutExtra("sms_body", messaggio) ' Inserisce il testo del messaggio
    StartActivity(smsIntent)
#end if
    'Dim p As Phone
    'Log(p.GetDataState) ' this asnwers "Connected"
    MySms.Send(Num, msg)' True, True)
#if xxx
    Try
      '  Dim numeroDestinatario As String = "1234567890" ' Numero del destinatario
       ' Dim testoMessaggio As String = "Testo del messaggio" ' Messaggio da inviare
       
        ' Creazione dell'oggetto SmsManager
        Dim sm As JavaObject
        sm.InitializeStatic("android.telephony.SmsManager")
       
        ' Ottenimento dell'istanza predefinita di SmsManager
        Dim smsManager As JavaObject = sm.RunMethod("getDefault", Null)
       
        ' Invio del messaggio
        smsManager.RunMethod("sendTextMessage", Array(Num, Null, msg, Null, Null))
       
        Log("SMS inviato con successo a: " & Num)
    Catch
        Dim ex As JavaObject = LastException
        Log("Errore durante l'invio dell'SMS: " & LastException)
        Log("Causa originale: " & ex.RunMethod("getCause", Null)) ' Mostra la causa sottostante
    End Try
#end if
End Sub

Private Sub PE_SmsDelivered (PhoneNumber As String, Intent As Intent)
   Log("Delivered")
   Delivered=True
    lblRisultato.Text="Mensagem enviada"
End Sub

Private Sub PE_SmsSentStatus (Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent)
    Log("SMS SENTSTATUS" & Success)
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub


Sub RiceveSms(Cmd As String)
    'ToastMessageShow("Recv:" & Cmd,True)
    Log("Riceve " & Cmd)
    Dim su As StringUtils
    lblRisultato.Text=su.DecodeUrl(Cmd,"UTF8")
   
End Sub
 
Upvote 0

teddybear

Well-Known Member
Licensed User
A project is attached, see what results for the permissions
 

Attachments

  • SMStest.zip
    11.6 KB · Views: 9
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
I don't know if this can help you, but in my app:

Manifest:
B4X:
AddPermission(android.permission.SEND_SMS)

Activity_Create:
B4X:
    For Each per In Array(rp.PERMISSION_SEND_SMS)
        rp.CheckAndRequest(per)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        If Not (Result) Then
            Msgbox("No permission, no party","")
            Activity.Finish
            Return
        End If
    Next


B4X:
Sub SendLargeSms(Destination As String, Message As String)
    Dim r As Reflector
    r.Target = r.RunStaticMethod("android.telephony.SmsManager", "getDefault", Null, Null)
    Dim parts As Object
    parts = r.RunMethod2("divideMessage", Message, "java.lang.String")
    r.RunMethod4("sendMultipartTextMessage", _
        Array As Object(Destination, 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

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
I don't know if this can help you, but in my app:

Manifest:
B4X:
AddPermission(android.permission.SEND_SMS)

Activity_Create:
B4X:
    For Each per In Array(rp.PERMISSION_SEND_SMS)
        rp.CheckAndRequest(per)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        If Not (Result) Then
            Msgbox("No permission, no party","")
            Activity.Finish
            Return
        End If
    Next


B4X:
Sub SendLargeSms(Destination As String, Message As String)
    Dim r As Reflector
    r.Target = r.RunStaticMethod("android.telephony.SmsManager", "getDefault", Null, Null)
    Dim parts As Object
    parts = r.RunMethod2("divideMessage", Message, "java.lang.String")
    r.RunMethod4("sendMultipartTextMessage", _
        Array As Object(Destination, Null, parts, Null, Null), _
        Array As String("java.lang.String", "java.lang.String", _
        "java.util.ArrayList", "java.util.ArrayList", "java.util.ArrayList"))
End Sub
Thanks, but nothing to do..
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
A project is attached, see what results for the permissions

Thank you, but it gives another error. This is the log of your App.

*** Service (s1) Create ***
** Service (s1) Start **
true
true
true
Error occurred on line: 80 (Main)
java.lang.SecurityException: com.android.phone from uid 10183 not allowed to perform READ_PHONE_STATE
at android.os.Parcel.createExceptionOrNull(Parcel.java:3011)
at android.os.Parcel.createException(Parcel.java:2995)
at android.os.Parcel.readException(Parcel.java:2978)
at android.os.Parcel.readException(Parcel.java:2920)
at com.android.internal.telephony.ISms$Stub$Proxy.sendTextForSubscriber(ISms.java:1482)
at android.telephony.SmsManager$1.onSuccess(SmsManager.java:639)
at android.telephony.SmsManager.sendResolverResult(SmsManager.java:1651)
at android.telephony.SmsManager.resolveSubscriptionForOperation(SmsManager.java:1612)
at android.telephony.SmsManager.sendTextMessageInternal(SmsManager.java:634)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:475)
at anywheresoftware.b4a.phone.Phone$PhoneSms.Send2(Phone.java:685)
at anywheresoftware.b4a.phone.Phone$PhoneSms.Send(Phone.java:664)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.TestSMS.main._send_click_1(main.java:612)
at b4a.TestSMS.main._send_click(main.java:601)
at java.lang.reflect.Method.invoke(Native Method)
 
Upvote 0
Top