Android Question event: a sms is sent - how to trap the event?

vangogh

Active Member
Licensed User
Longtime User
my app sends sms, the sending works OK

but I can't trap the event "sms sent"

What am I doing wrong?



thank you!


sens sms:
'in the manifest I have
'AddPermission(android.permission.SEND_SMS)
'AddPermission(android.permission.RECEIVE_SMS)
'AddPermission(android.permission.READ_PHONE_STATE)
' Ok, all the permission programming code here is not pasted, but trust mw it's done and working

' code

Sub Class_Globals
    '(cut)
    Dim PEsms As PhoneEvents ' per notifica invio SMS
    '(cut)
end sub

Private Sub B4XPage_Created (Root1 As B4XView)
    '(cut)
    PEsms.Initialize("PEsms")
    '(cut)
end sub


private Sub btnInvioDiretto_Invia_Click

    'THIS WORKS

    Dim ps As PhoneSms
    ps.Send2(InvioDiretto_NumeroTelefono.Text, InvioDiretto_TestoMessaggio.Text, False, False)
 
    ToastMessageShow ("SMS inviato a " & InvioDiretto_NumeroTelefono.Text, True)
 
    'THIS WORKS, the sms is sent
 
End Sub


Sub PEsms_SmsDelivered (PhoneNumber As String, Intent As Intent)

    ' THIS DOESN'T WORK
    ' this event is NEVER raised

    Log("SMS Delivered: PhoneNumber=" & PhoneNumber & ", message_id=" & Intent.GetExtra("message_id"))
    ToastMessageShow("SMS INVIATO: " & PhoneNumber, True)

End Sub


Sub PEsms_SmsSentStatus (Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent)

    ' THIS DOESN'T WORK
    ' this event is NEVER raised

    Log("phs_SmsSentStatus: PhoneNumber=" & PhoneNumber & ", Success=" & Success & ", Err=" & ErrorMessage & ", message_id=" & Intent.GetExtra("message_id"))
    ToastMessageShow("SMS INVIO: esito=" & Success & " -err=" & ErrorMessage, True)

End Sub
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Only the default-sms-app on the device does have this rights.

Guess your app is not the default-smsapp. That´s probably why you do not get any status.

See

The following types of objects can no longer be used:

- CallLog
- SmsMessages
- PhoneSms
- SmsInterceptor (and the equivalent static intent filter)
 
Upvote 0

vangogh

Active Member
Licensed User
Longtime User
Only the default-sms-app on the device does have this rights.

Guess your app is not the default-smsapp. That´s probably why you do not get any status.

See

it seems that this is true only when my app is published in google play (?)

my app is NOT on google play

I send sms with no problems, and it is not allowed when the app is in google play... but I do.

So perhaps i could/should receive the sms sending status (?)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
my app is NOT on google play
what is the targetsdk you are using in your app then if it is not on Playstore?

Maybe you MUST have your app set as the devices default-sms app. If that not is the case then you probably are NOT ALLOWED to see the status because of the new google-requirements. Even if not on Playstore
 
Upvote 0

vangogh

Active Member
Licensed User
Longtime User
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33"/>


if "maybe I am not allowed"... maybe... I need to continue investigating ;-)
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i don't think SmsDelivered is guaranteed. i believe it depends on the policies of the recipient's phone service.
 
Upvote 0

vangogh

Active Member
Licensed User
Longtime User
i don't think SmsDelivered is guaranteed. i believe it depends on the policies of the recipient's phone service.

RIGHT

> but I can't trap the event "sms sent"
I mean "the sms is actually sent" - I don't need to know if it is received from the recipient

I use the .Send2 method so the sms goes in the "to be sent" recipient of the phone, that sends the sms when it can (maybe it is offline...)
I need to know when the SMS is SENT (out from my phone)

SO in my code:

(maybe) i don't need to make THIS working -> Sub PEsms_SmsDelivered

but (maybe) i need to make THIS working-> Sub PEsms_SmsSentStatus

(but both doesn't work - the event is never raised)

THANK YOU!
 
Last edited:
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Looking at the documentation of PhoneSMS.Send2

Method_636.png
Send2 (PhoneNumber As String, Text As String, ReceiveSentNotification As Boolean, ReceiveDeliveredNotification As Boolean)​

Sends an Sms message. Note that this method actually sends the message (unlike most other methods that

create an intent object).
You can use PhoneEvents to handle the SmsSentStatus and SmsDelivered events.
ReceiveSentNotification - If true then the SmsSentStatus event (PhoneEvents) will be raised when the message is sent.
ReceiveDeliveredNotification - If true then the SmsDelivered event (PhoneEvents) will be raised when the message is delivered.
Note that the two above notifications might incur an additional payment.
Should you not be using
B4X:
Dim ps As PhoneSms
ps.Send2(InvioDiretto_NumeroTelefono.Text, InvioDiretto_TestoMessaggio.Text, True, False) 'Note that the 3rd parameter is now set to True
to get the sent notification event?
Or
B4X:
Dim ps As PhoneSms
ps.Send2(InvioDiretto_NumeroTelefono.Text, InvioDiretto_TestoMessaggio.Text, True, True) 'Note both the 3rd and fourth parameter are now set to True
if you want both the sent and delivered notification events?

Link:
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
yes, but if you use a higher targetSDK then


you´ll find out that it ONLY works if your app is the default SMS app.
In all other cases you do not get any permission to get the result.

The following types of objects can no longer be used:

- CallLog
- SmsMessages
- PhoneSms
- SmsInterceptor (and the equivalent static intent filter)
 
Last edited:
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
@OliverA is right: the last 2 arguments of smssend2 need to be "true" and "true", not "false" and "false".
however, using plain, old "smssend()" is the same as using "smssend2()" with "true" and "true". it's a convenience method.

as to the smssent event, it isn't raised.

i send text messages from an android 14 (sdk33) pixel device all the time (i also use a broadcast receiver to intercept incoming messages). the messages i send are received. the delivered event is raised (see attached), but not the sent event. even if a ratchet back to sdk28, it's still an android 14. in any case sdk28 doesn't help.
there are some entries in the log from the imsmanager relating to status, but nothing reaches the b4a level.
 

Attachments

  • sms.png
    sms.png
    28.6 KB · Views: 33
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
here are 2 log entries relating to the smssent and smsdelivered pendingintents sent by our phone library (which include phone events and sendsms):

android.app.StackTrace: New mutable implicit PendingIntent: pkg=com.georgieapps.smser, action=b4a.smssent, featureId=null. This will be blocked once the app targets U+ for security reasons.
android.app.StackTrace: New mutable implicit PendingIntent: pkg=com.georgieapps.smser, action=b4a.smsdelivered, featureId=null. This will be blocked once the app targets U+ for security reasons.

note how google says both of these intents will be blocked in the future (which sounds very near, judging by the target reference).
 
Upvote 0
Top