SMS sent / delivered: how do you determine which SMS items belong to?

In the stream How to track each status of a sent SMS? described how you can track the status of sent / delivered SMS via broadcast.

However, I did not find: how do you determine to which SMS the transmission relates? As far as I know, there seems to be no information in getResultData () and getResultExtras ().

My use case: I send several SMS in a loop one by one. I want to track delivery status / success for each message. How to find out which broadcast belongs to which message. (Delaying the delivery of each sms until I received a broadcast for each previous one is actually not an option).

+4
source share
1 answer

Matthias,

Referring to the code in your related question. When you create an Intent that PendingIntent will run instead of just giving it an Action String , you can add additional information to it to 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); 

Thus, you should be able to get the value "smsNumber" inside the BroadcastReceiver

Hope this helps!

Edit Matthias Lin: It is important that you pass the FLAG_UPDATE_CURRENT flag with the expectation that additional data is transmitted and actually received with the broadcast.

+5
source

All Articles