SmsDelivered and SmsSentStatus always return last number

AirLink

Member
Licensed User
Longtime User
Hi Erel!
I'm having trouble with the Phone Library events SmsDelivered & SmsSentStatus.
The events are raised after multiple sms send commands but the phone number returned is always the last one in the batch.

example:
mysms.send ("xxxxxx01","Test1")
mysms.send ("xxxxxx02","Test2")
mysms.send ("xxxxxx03","Test3")

The events are raised 3 times but the returned PhoneNumber is always "xxxxxx03"

The events are in a service module and the code is below:

B4X:
Sub Process_Globals
Dim PhoneId As PhoneId
Dim PE As PhoneEvents
End Sub

Sub Service_Create
PE.InitializeWithPhoneState("PE", PhoneId)
Dim SI As SmsInterceptor
SI.Initialize2("SI", 999)
End Sub

Sub PE_SmsSentStatus (Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent)
Log ("SMSSentStatus:" & Success & ":" & ErrorMessage & ":" & PhoneNumber, True)
End Sub

Sub PE_SmsDelivered (PhoneNumber As String, Intent As Intent)
Log ("Receipt from " & PhoneNumber & CRLF)
End Sub

Am I missing something?
Thanks!
 

Sorin Pohontu

Member
Licensed User
Longtime User
Hello. I know this thread is old, but I have stumble across same issue.

Erel: allow me to make a correction. I have seen your code for Send from Phone Library (https://www.b4x.com/android/forum/threads/sendsms-delivery-and-sent-intents.28054/#post-162603).
The problem arise because it's using same requestCode on each request (0), with PendingIntent.FLAG_UPDATE_CURRENT.
On each message sent, Extra information is updated [see putExtra("phone")] with the information form most recent message.

A better approach is to generate a Random/Unique requestCode for each Send().
In this way, you'll get a different Intent on each request and you'll have correct info on SmsSentStatus/SmsDelivered.

I've just made a test using inline Java Code (btw, thanks for this feature in B4A 4.30) and made a new Send function and everything works as expected.

I'll get back with another post in PhoneUpdate library, with a few improvements in Send (handling Multipart-Messages and adding custom Extra), as soon as my inline Java Code is working as desired

Have a nice day,
/Sorin
 

Sgardy

Member
Licensed User
Longtime User
Hello friends, I hope this is not off topic but I have a little doubt about these phone events, I made a routine that send SMS and check with "PE_SmsSentStatus" that all is going right, well it works fine, even to much! Infact SmsSentStatus add the return receipt to the messages that cost money! I burned 50 euros in a couple of day, asking to my provider if something was going wrong they told me that even if I have free messages plain the receipt have a cost, and all my last messages were asking for it, I didn't believe that but checking the messages properties I discovered that that was the bitter truth. So what I have to do? I want just that the app retry to send in case of bad radio coverage and nothing else. Thanks for help!
 

Sgardy

Member
Licensed User
Longtime User
Hello friends, I hope this is not off topic but I have a little doubt about these phone events, I made a routine that send SMS and check with "PE_SmsSentStatus" that all is going right, well it works fine, even to much! Infac...

I reply by my self... I've seen that I should use Send2 instead Send flagging to false the receiveNotifications, but in this case how to check if it's impossible to send when in a shadow radio area? Thanks again!
 

Sgardy

Member
Licensed User
Longtime User
Thank you Erel! Great as ever I tried just now and it seems to be not charged, I suggest to set to false by default the flags in PhoneSms.Send because the beginners (like me) may realize to late about charging!
Ciao
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…