Android Question Simple SMS send not working

Gino_VDS

Member
Licensed User
I am a newbie. I would like to develop some apps with SMS functionality. Later on with the purpose of sending commands to an Arduino.
But It seems I stumble into a critical problem.

The code is sourced from a book, a simple text SMS send example. It should work but it doesn't.
Installation of the app via bridge is fine.
When this app is running and if push the send button the apps STOPS and the debug window returns this:

Error occurred on line: 41 (Main)
java.lang.SecurityException: Neither user 10463 nor current process has android.permission.READ_PHONE_STATE.


I’ve tried to add some rules in the manifest file but unfortunately without any luck:
AddPermission(android.permission.SEND_SMS)
AddPermission(android.permission.READ_PHONE_STATE

The same problem remains. The app halts + same error in the debug window.

It seems I am still stuck in some way. Somebody...?
My phone has Android OS 8.0.0.
Code attached.
 

Attachments

  • SMS send issue.zip
    1.9 KB · Views: 200

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. You are not requesting permissions correctly. See the video tutorial: Runtime Permissions (Android 6.0+ Permissions)

2. Please post the full error message from the logs.

3. If the READ_PHONE_STATE is really needed then you need to do two things:

- Add it to the manifest editor:
B4X:
AddPermission(android.permission.READ_PHONE_STATE)

- Request it before you send the message:
B4X:
Sub SEND_Click
   For Each permission As String In Array(rp.PERMISSION_READ_PHONE_STATE, rp.PERMISSION_SEND_SMS)
       rp.CheckAndRequest(permission)
       Wait For Activity_PermissionResult (permission As String, Result As Boolean)
       If Result = False Then
           ToastMessageShow("No permission", True)
           Return
       End If
   Next
   Dim msg As String
   msg = Command.Text
   MySms.Send2("07391846950", msg, True, True)
End Sub
 
Upvote 0
Top