Android的短信给没有更新的意图包吐司信息 [英] Android sms intent bundle toast info not updating
本文介绍了Android的短信给没有更新的意图包吐司信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我送2个短信息,我想有2烤面包的消息
1)短信发送 - 第一号以及
2)短信发送 - 第二个数字
不过,我得到2敬酒的消息均显示消息
1),发生什么事,以信息
2)?缺少了什么?
感谢。
registerReceiver(新广播接收器(){
@覆盖
公共无效的onReceive(上下文为arg0,ARG1意向){
开关(的getResult code())
{
案例Activity.RESULT_OK:
Toast.makeText(getBaseContext(),短信发送 - + arg1.getStringExtra(的SendTo),
Toast.LENGTH_LONG).show();
打破;
}
}
},新的IntentFilter(SENT)); SmsManager短信= SmsManager.getDefault();
意向意图=新意图(发送);
intent.putExtra(的SendTo,第一个数字);
的PendingIntent sentIntents = PendingIntent.getBroadcast(这一点,0,意向,0);
sms.sendTextMessage(1234,空,消息,sentIntents,NULL); 意图intent1 =新意图(发送);
intent1.putExtra(的SendTo,第二个数字);
的PendingIntent sentIntents1 = PendingIntent.getBroadcast(在此,0,intent1,0);
sms.sendTextMessage(456,空,消息,sentIntents1,NULL);
解决方案
你在做什么是 - 使用相同的intent.So你必须更新的意图和更改请求code,这样的结果不重叠。
见following.Following code会工作。
registerReceiver(新广播接收器(){
@覆盖
公共无效的onReceive(上下文为arg0,ARG1意向){
开关(的getResult code())
{
案例Activity.RESULT_OK:
Toast.makeText(getBaseContext(),短信发送 - + arg1.getStringExtra(的SendTo),
Toast.LENGTH_LONG).show();
打破;
}
}
},新的IntentFilter(SENT)); SmsManager短信= SmsManager.getDefault();
意向意图=新意图(发送);
intent.putExtra(的SendTo,第一个数字);
的PendingIntent sentIntents = PendingIntent.getBroadcast(这一点,0,意向,PendingIntent.FLAG_UPDATE_CURRENT);
sms.sendTextMessage(5556,空,消息,sentIntents,NULL); 意图intent1 =新意图(发送);
intent1.putExtra(的SendTo,第二个数字);
的PendingIntent sentIntents1 = PendingIntent.getBroadcast(这一点,1,intent1,PendingIntent.FLAG_UPDATE_CURRENT);
sms.sendTextMessage(5556,空,消息,sentIntents1,NULL);
I am sending 2 sms messages, i want to have 2 toast messages with
1) "SMS sent - first number" and
2) "SMS sent - second number"
however, am getting 2 toast messages both showing message
1), what happen to message
2)? what's missing?
thanks.
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);
解决方案
What you are doing is -using the same intent.So you have to update the intents and change the request code so that result not overlapped . See the following.Following code will work.
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的短信给没有更新的意图包吐司信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文