Android Question Handling SMS delivery notifications

pxpto

Member
Licensed User
Longtime User
Hi, I have an app that sends SMS and I want to start monitoring the delivery reports to be sure that the messages were in fact delivered to the other side.

This is the part of the code that matters:

B4X:
Dim ThisPhoneSms As PhoneSms
Dim PhoneId As PhoneId
Dim PE As PhoneEvents

(...)

PE.InitializeWithPhoneState("PE", PhoneId)

(...)

ThisPhoneSms.Send("+" & SMSDestination, SMSMessage)

(...)

Sub PE_SmsDelivered (PhoneNumber As String, Intent As Intent)
    Log ("Receipt from: " & PhoneNumber)
    Log ("Receipt Intent: " & Intent)
    Log ("Receipt GetData: " & Intent.GetData)
    Log ("Receipt Action: " & Intent.Action)
    Log ("Receipt Flags: " & Intent.Flags)
    Log ("Receipt ExtrasToString: " & Intent.ExtrasToString)
End Sub

And this works. I get the delivery report. But when the destination phone is Airplane mode (no network) and the SMS is kept in the Service Center I receive one delivery report, and when I turn the destination phone back ON I get another delivery report with different PDU content.

This is my log when I send the SMS to a mobile phone that is in Airplane mode:

> Sending SMS to xxxxxxxxxxxx
> SMSSentStatus:true:OK:+xxxxxxxxxxxx

I receive this a few seconds after the SMS has been sent:

> Receipt from: +xxxxxxxxxxxx
> Receipt Intent: (Intent) Intent { act=b4a.smsdelivered flg=0x10 (has extras) }
> Receipt GetData: null
> Receipt Action: b4a.smsdelivered
> Receipt Flags: 16
> Receipt ExtrasToString: Bundle[{format=3gpp, pdu=[B@9015592, phone=+xxxxxxxxxxxx}]

Then I take the destination phone from Airplane mode so it receives the SMS and I get this:

> Receipt from: +xxxxxxxxxxxx
> Receipt Intent: (Intent) Intent { act=b4a.smsdelivered flg=0x10 (has extras) }
> Receipt GetData: null
> Receipt Action: b4a.smsdelivered
> Receipt Flags: 16
> Receipt ExtrasToString: Bundle[{format=3gpp, pdu=[B@e901b63, phone=+xxxxxxxxxxxx}]

So the first delivery report should tell me that the SMS was sent but not delivered to the destination (pending in the Service Center).. and the second delivery report should tell me that the SMS was actually delivered to the destination.

My question is how to know the diference between "sent/pending" and "delivered" based on the PDU code received? Because I cannot be sure that the PDU will be the same on all phones/networks.

Thanks in advance!
 

pxpto

Member
Licensed User
Longtime User
I don't think that you can find this information from the PDU code. Are you sending multiple SMS messages to the same phone number?

From what I've seen, I should be able to decode the pdu and get that information. But according to all the documentation I saw, the pdu should be a little larger, including the destination number, delivery date/time, etc.

https://en.m.wikipedia.org/wiki/GSM_03.40

I'm using the Android device as an sms gateway to deliver sms's to several different destinations, so I need a reliable delivery report.
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
Upvote 0

pxpto

Member
Licensed User
Longtime User
T
(Is large. But how do we access it in such case ?)

This is not large. It's 3,5 bytes. The full pdu should be something like 30-40 bytes.

When the gsm operator wants to inform me thay my sms was delivered it sends me a pdu which includes the destination number, delivery date, error code, etc. As B4A is triggering an event where it already shows me the destination number, it means B4A is already parsing that big pdu received by the operator, but it's not showing me all the information. I respect that, but the full pdu should be available (or decode more fields in the intent).
 
Upvote 0

pxpto

Member
Licensed User
Longtime User
Normal unicode sms 160 charters. Phone auto divide your sms when you have long sms (220 char, you check sms with links under below).
Result ; you will revice delivery report for each sms part

I think, Maybe these links help you
http://spin.atomicobject.com/2011/04/20/concatenated-sms-messages-and-character-counts/
http://messente.com/documentation/sms-length-calculator
https://en.wikipedia.org/wiki/GSM_03.38

Thank you for your reply. Im aware of those limitations and I am already dealing with them. The problem here are the delivery reports that appear not to be showing all the information available.
 
Upvote 0

pxpto

Member
Licensed User
Longtime User
I have added that to PE_SmsDelivered

B4X:
Dim data1() As Byte = Intent.GetExtra("pdu")
Dim bc As ByteConverter
Log(bc.HexFromBytes(data1))

I have got the PDU. I submitted it at http://www.diafaan.com/sms-tutorials/gsm-modem-tutorial/online-sms-pdu-decoder/ and got all the information

Thatks a lot. I'll try that in a moment. How many bytes you got on your pdu? Could you please share the result you got on that online pdu decoder (hiding private info of course)?
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
Upvote 0

pxpto

Member
Licensed User
Longtime User
Upvote 0

pxpto

Member
Licensed User
Longtime User
Now one final question.

I was using this code to send my SMS's:

B4X:
Dim ThisPhoneSms As PhoneSms
ThisPhoneSms.Send("+" & SMSDestination, SMSMessage)

With this code, I can send the SMS and receive the delivery reports with the correct PDU, etc. Perfect.

But to be able to send long SMS's I use a different code that I saw somewere in the forums:

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

But using this code I don't get PE_SmsDelivered event. How can I fix this? How can I receive the delivery reports using this code, or how can I use the first code to send long SMS's and receiving the delivery report?
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
But using this code I don't get PE_SmsDelivered event. How can I fix this
I am sorry not to have time to work on this at the moment. But perhaps could you find the solution here : http://developer.android.com/refere...va.util.ArrayList<android.app.PendingIntent>)
The difficulty will be to manage the receipts for all the sub parts of the MultipartTextMessage

deliveryIntentsArrayList: if not null, an ArrayList of PendingIntents (one for each message part) that is broadcast when the corresponding message part has been delivered to the recipient. The raw pdu of the status report is in the extended data ("pdu").
 
Upvote 0
Top