tags:

views:

289

answers:

1

Hi,

I'd like to send an sms message. If the text is too long, I split it into multiple messages. I'm trying to put some extra info into the "sent" intent to know which part has been sent, and when all the parts are complete:

ArrayList<String> messageParts = ...;
for (int i = 0; i < messageParts.size(); i++) {
    sms.sendTextMessage(
      address, 
      null, 
      messageParts.get(i), 
      generateIntent(context, messageParts.size(), i), 
      null));
}

PendingIntent generateIntent(Context context, int partCount, int partIndex)
{
    Intent intent = new Intent("SMS_SENT");
    intent.putExtra("partCount", partCount);
    intent.putExtra("partIndex", partIndex);
    return PendingIntent.getBroadcast(context, 0, intent, 0);
}

The message is sent, and I catch the intent when each part is sent - but the intent always has the same data in it. For example, "partIndex" is always zero, even though for the second message, it should be one. Seems like the same intent just keeps getting thrown to my broadcast receiver. What's the right way to do this?

Thanks

+3  A: 

Try using FLAG_ONE_SHOT or otherwise canceling the previous PendingIntent before trying to create a new one.

CommonsWare
Exactly; you need to tell the framework not to reuse the same `PendingIntent`. Though for sending multiple messages, can you not just use the `sendMultipartTextMessage` method?
Christopher
I used PendingIntent.FLAG_CANCEL_CURRENT flag and sendMultipartTextMessage in my code.
Samuh