Keeping track of sms sent in Android

2019-06-24 09:40发布

I'm noticing the tracking pending intents that I send out via the standard SmsManager in Android doesn't seem to retain the extra information in them. Example:

Intent sentIntent = new Intent(SENT);
sentIntent.putExtra("value1", "foo"); // <- note this value
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent, 0);

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(numberToSendTo, null, mMessageToSend, sentPI, null);

//... in the broadcastReceiver that catches the SENT intent ...
public void onReceive(Context arg0, Intent arg1) {

    arg1.getExtras().getString("value1");  // <- nothing, no such key
}

Can someone test this out, was this behaviour intended and I am doing it wrong, or is this a bug to be filed for Android?

标签: android sms
1条回答
相关推荐>>
2楼-- · 2019-06-24 10:40

Try adding the flag FILL_IN_SELECTOR when you create the PendingIntent (see the spec for PendingIntent.getBroadcast for the flags and their general behavior). This should force the PendingIntent to take in all the top-level extras from the Intent.

查看更多
登录 后发表回答