Android Question Sending SMS by PhoneSMS incl. capturing of 'Message Sent' and 'SMS Received' events etc.


Active Member
Licensed User

I have a doubt.

1) I am unable to send SMS by using PhoneSMS.

I have attached a sample source code.

In the attached code, I tried the solution given earlier of sending sms via 'Intent' (the relevant lines are commented in that code with a 'X ).

Though that code worked fine, I had to explicitly press the 'Send' button on the Phone to send the SMS.

The solution given in the forum to this was that we should use the PhoneSMS library (and also since my app is not to be published under Google Play so .. those restrictions do not apply)..

The error message shown is below.

It is to inform that the program when started does not ask for any enabling of permissions - it simply hangs...

2) Assuming this is possible, can someone post an example of how to capture the 'SMS Sent', 'SMS Received' events etc..

Please help.


The Error message :

Logger connected to: Xiaomi Redmi Note 7 Pro
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 352)
java.lang.SecurityException: Sending SMS message: uid 10239 does not have android.permission.SEND_SMS.
at android.os.Parcel.createException(
at android.os.Parcel.readException(
at android.os.Parcel.readException(
at android.telephony.SmsManager.sendTextMessageInternal(
at android.telephony.SmsManager.sendTextMessage(
at b4a.example.main._activity_create(
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(
at b4a.example.main.afterFirstLayout(
at b4a.example.main.access$000(
at b4a.example.main$
at android.os.Handler.handleCallback(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at java.lang.reflect.Method.invoke(Native Method)


    9.1 KB · Views: 55


Licensed User
Only the default SMS App on your Device is allowed to Send SMS.
I earlier Androids it was possible
Upvote 0


Active Member
Licensed User
Only the default SMS App on your Device is allowed to Send SMS.
I earlier Androids it was possible
Hi Don,

Thanks ... So is it that I am better off with the 'Intent' way of sending the SMS (as opposed to the PhoneSMS thing)?

The result would be that the Message to be sent is 'readied' by the application and shown to the end-user and end-user has to 'explicitly press the SEND' button and then the Message goes ...

Please correct me if I am wrong ..

Secondly, since there were no replies to my Doubt 2 above, does it mean that PhoneSMS Library is not relevant today and should no longer be used by Android developers ?

Again.. please correct me if I am wrong..

Last edited:
Upvote 0


Well-Known Member
Licensed User
Your error is shown below:
java.lang.SecurityException: Sending SMS message: uid 10239 does not have android.permission.SEND_SMS.

In the settings app on your phone, you need to find 'apps and notifications' (may be called something different based on your phone) > find your app > need to enable the SMS permission, then it will allow you to send SMS messages within the app.

I have used a Pixel4a (Running Android 11 - not-rooted) and got it to send the SMS and also receive the SMS in my B4A app.

I am not submitting it to Google Play so it's possible to be done. (If you upload the app to Google Play then it will get rejected by Google as SMS apps are not allowed on Google Play).

Here is how I got it to work:

' Send SMS with this code. (I am sending it from the starter service)
Dim p As PhoneSms
' replace phonenumber with the phone number you want to send the SMS to
' replace msg with the message you want to send

Receive SMS:
Sub Service_Create
    Dim SI As SmsInterceptor
    SI.Initialize2("SI", 999)
End Sub

' Default SMS app on the phone still gets the SMS
Public Sub SI_MessageReceived (From As String, Body As String) As Boolean
    Log($"From: ${From}, Body: ${Body}"$)
End Sub
Upvote 0


Active Member
Licensed User
Hi Aaronk,

Thanks a lot !

It worked !

I selected Permissions and 'allowed' SMS for my app - and it works - meaning there is no need to press the Send button now - it automatically sends the message upon code invokation using PhoneSMS (I did not use the Intent method).

One more request.

What does 999 in your SI.Initialize2("SI", 999) stand for ?

Please guide me.

2) From your reply I understand that I should be able to invoke a database from this SI_MessageReceived event and trap all messsages and store it in a database..

The intention here is to keep track of the 'responses' related to that 'Service Domain' for which the message is intended for. One could then request the end-user to prefix the messages with a specific Domain Name , for example, 'XYZPetServices:I have accepted your response' where XYZPetServices is the 'Service Domain'. From this it would be easier to sift through all messages related to that particular domain.

Please correct me if I am wrong.

Last edited:
Upvote 0