Mathias Conradt
Mathias Conradt

Reputation: 28665

Sent/delivered SMS: how do you identify to which SMS the broadcast belongs?

In thread How to monitor each of Sent SMS status? it is described how you can monitor the status of a sent/delivered SMS via broadcast.

However, I haven't found: how do you identify to which SMS the broadcast belongs? There doesn't seem to be any information in getResultData() nor getResultExtras() as far as I have checked.

My use case is: I send multiple SMS in a loop one right after another. I want to monitor the status/success of the deliver for each message. How do I know which broadcast belongs to which message. (Delaying the delivery of each sms until I've gotten a broadcast for each previous one isn't really an option).

Upvotes: 4

Views: 3415

Answers (1)

Will Tate
Will Tate

Reputation: 33509

Mathias,

Referring to the code in the question you linked. When you create the Intent to be launched by the PendingIntent instead of just giving it an Action String you can add an extra to it to help determine which SMS it belongs to...

Intent sentIntent = new Intent(SENT);
sentIntent.putExtra("smsNumber", someValue);
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent, FLAG_UPDATE_CURRENT);

Intent deliveredIntent = new Intent(DELIVERED):
deliveredIntent.putExtra("smsNumber", someValue);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, deliveredIntent, FLAG_UPDATE_CURRENT);

This way you should be able to retrieve the "smsNumber" value inside the BroadcastReceiver

Hope this helps!

Edit by Mathias Lin: Important that you pass the flag FLAG_UPDATE_CURRENT with the pending intent, so that the extras get passed along and actually arrive with the broadcast.

Upvotes: 5

Related Questions