我如何从待处理的意图中获取请求代码以显示传递的消息
How i can get requestcode from pending intent for showing which message delivered
我想在发送后显示消息状态
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);
发送短信时,我想从PendingIntent
获取requestcode
以显示发送了哪些短信,但是在onReceive()
方法中我无法获取requestcode
您应该像这样将您的短信 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...
}
我想在发送后显示消息状态
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);
发送短信时,我想从PendingIntent
获取requestcode
以显示发送了哪些短信,但是在onReceive()
方法中我无法获取requestcode
您应该像这样将您的短信 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...
}