开发者

Putting data in the SMS sent intent?

开发者 https://www.devze.com 2022-12-15 07:08 出处:网络
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

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 alwa开发者_Go百科ys 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


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


You need to add a unique request code to your broadcast (second argument to getBroadcast method) in order to send unique values across. See this other question for more details: Differentiating delivery reports of two separate SMS's

0

精彩评论

暂无评论...
验证码 换一张
取 消