Android的短信不更新意图束敬酒信息(Android sms intent bundle toa

2019-09-17 18:58发布

我送2个短信息,我想有2层烤面包的消息

1)“SMS发送 - 第一号”和

2) “SMS发送 - 第二个数字”

然而,我越来越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);

Answer 1:

你在做什么的 - 使用相同intent.So你有更新的意图和变更请求的代码,这样的结果并不重叠。 见following.Following代码将工作。

 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);


Answer 2:

改成这样:

Toast.makeText(this, "First number", Toast.LENGTH_SHORT).show();
sms.sendTextMessage("1234", null, message, null, null);
Toast.makeText(this, "Second number", Toast.LENGTH_SHORT).show();
sms.sendTextMessage("456", null, message, mull, null);


文章来源: Android sms intent bundle toast info not updating