我有意图在发送
后显示消息状态private void sendSMS(String phoneNumber, String message)
{
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
这是我未决的意图
deliveredPI = PendingIntent.getBroadcast(this, id, new Intent(DELIVERED), 0);
当短信发送时,我想从requestcode
获取PendingIntent
以显示已发送的短信,但在onReceive()
方法中我无法获取requestcode
答案 0 :(得分:0)
您应将短信id
添加到PendingIntent
,如下所示:
Intent deliveryIntent = new Intent(DELIVERED);
deliveryIntent.putExtra("id", id);
deliveredPI = PendingIntent.getBroadcast(this, id, deliveryIntent, 0);
然后,在onReceive()
中,您可以获得这样的短信ID:
int id = intent.getIntExtra("id", -1);
if (id >= 0) {
// Got a valid id...
}