我正在发送两条短信,我想有两条吐司信息
1)“发送短信-第一个号码”和
2)“发送短信-第二个号码”
但是,我收到两条吐司消息,都显示消息
1)消息发生了什么
2)?少了什么?
谢谢。
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent - " + arg1.getStringExtra("SendTo"),
Toast.LENGTH_LONG).show();
break;
}
}
}, new IntentFilter(SENT));
SmsManager sms = SmsManager.getDefault();
Intent intent = new Intent(SENT);
intent.putExtra("SendTo", "first number");
PendingIntent sentIntents = PendingIntent.getBroadcast(this, 0, intent, 0);
sms.sendTextMessage("1234", null, message, sentIntents, null);
Intent intent1 = new Intent(SENT);
intent1.putExtra("SendTo", "second number");
PendingIntent sentIntents1 = PendingIntent.getBroadcast(this, 0, intent1, 0);
sms.sendTextMessage("456", null, message, sentIntents1, null);
最佳答案
你所做的是-使用相同的意图。所以你必须更新意图并更改请求代码,这样结果就不会重叠。
请参阅下面的代码。下面的代码将起作用。
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent - " + arg1.getStringExtra("SendTo"),
Toast.LENGTH_LONG).show();
break;
}
}
}, new IntentFilter(SENT));
SmsManager sms = SmsManager.getDefault();
Intent intent = new Intent(SENT);
intent.putExtra("SendTo", "first number");
PendingIntent sentIntents = PendingIntent.getBroadcast(this, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
sms.sendTextMessage("5556", null,message, sentIntents, null);
Intent intent1 = new Intent(SENT);
intent1.putExtra("SendTo", "second number");
PendingIntent sentIntents1 = PendingIntent.getBroadcast(this, 1, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
sms.sendTextMessage("5556", null, message, sentIntents1, null);
关于android - Android短信Intent bundle toast 信息未更新,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10908886/