Keeping track of sms sent in Android

烈酒焚心 提交于 2019-12-23 12:33:36

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/10118242/keeping-track-of-sms-sent-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!