Android 广播接收器onReceive未获取目的包
我用下面的代码发送一条文本(套件前kat)。当我创建要传递到smsManager的intent时,我在intent中加了一个int。在广播接收器中,当我调用intent.getIntExtra时,它总是给我一个值0。你知道为什么吗 当我将onReceive中的I值打印到日志中时,每次都显示该值为0 下面是发送代码(这是一个for循环,所以“i”可以是0-10之间的任意值):Android 广播接收器onReceive未获取目的包,android,android-intent,android-broadcast,Android,Android Intent,Android Broadcast,我用下面的代码发送一条文本(套件前kat)。当我创建要传递到smsManager的intent时,我在intent中加了一个int。在广播接收器中,当我调用intent.getIntExtra时,它总是给我一个值0。你知道为什么吗 当我将onReceive中的I值打印到日志中时,每次都显示该值为0 下面是发送代码(这是一个for循环,所以“i”可以是0-10之间的任意值): 我认为您应该在数据中添加FILL\u或pendingent.FLAG\u UPDATE\u CURRENT标志: mS
我认为您应该在数据中添加
FILL\u
或pendingent.FLAG\u UPDATE\u CURRENT
标志:
mSmsManager.sendTextMessage(number, null, getFinalMessage(),
(PendingIntent.getBroadcast(getActivity(), 0, sentIntent,Intent.FILL_IN_DATA)),
(PendingIntent.getBroadcast(getActivity(), 0, deliveredIntent, Intent.FILL_IN_DATA)));
在发送另一条短信之前,请等待收到短信(RESULT\u OK
):
for (int i = 0; i < getSelectedNumbers().size(); i++) {
Log.d("Pete Debug", "Loop value of i = " + String.valueOf(i));
String number = removeSpecialCharacters(getSelectedNumbers().get(i));
String smsSending = "Sending to " + number + "... ";
Log.d("Pete Debug", smsSending);
statusItems = new SmsStatusItems();
statusItems.setMessage(smsSending);
statusItems.setImage(R.drawable.clock);
smsStatusAdapter.add(statusItems);
Intent sentIntent = new Intent(SMS_SENT);
sentIntent.putExtra(SMS_SENT, i);
Intent deliveredIntent = new Intent(SMS_DELIVERED);
deliveredIntent.putExtra(SMS_DELIVERED, i);
// This for waiting ;) put the other code here
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));
mSmsManager.sendTextMessage(number, null, getFinalMessage(),
(PendingIntent.getBroadcast(getActivity(), 0, sentIntent,Intent.FILL_IN_DATA)),
(PendingIntent.getBroadcast(getActivity(), 0, deliveredIntent, Intent.FILL_IN_DATA)));
}
for(int i=0;i
我认为您应该添加填写数据
或pendingent.FLAG\u UPDATE\u CURRENT
FLAG:
mSmsManager.sendTextMessage(number, null, getFinalMessage(),
(PendingIntent.getBroadcast(getActivity(), 0, sentIntent,Intent.FILL_IN_DATA)),
(PendingIntent.getBroadcast(getActivity(), 0, deliveredIntent, Intent.FILL_IN_DATA)));
在发送另一条短信之前,请等待收到短信(RESULT\u OK
):
for (int i = 0; i < getSelectedNumbers().size(); i++) {
Log.d("Pete Debug", "Loop value of i = " + String.valueOf(i));
String number = removeSpecialCharacters(getSelectedNumbers().get(i));
String smsSending = "Sending to " + number + "... ";
Log.d("Pete Debug", smsSending);
statusItems = new SmsStatusItems();
statusItems.setMessage(smsSending);
statusItems.setImage(R.drawable.clock);
smsStatusAdapter.add(statusItems);
Intent sentIntent = new Intent(SMS_SENT);
sentIntent.putExtra(SMS_SENT, i);
Intent deliveredIntent = new Intent(SMS_DELIVERED);
deliveredIntent.putExtra(SMS_DELIVERED, i);
// This for waiting ;) put the other code here
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));
mSmsManager.sendTextMessage(number, null, getFinalMessage(),
(PendingIntent.getBroadcast(getActivity(), 0, sentIntent,Intent.FILL_IN_DATA)),
(PendingIntent.getBroadcast(getActivity(), 0, deliveredIntent, Intent.FILL_IN_DATA)));
}
for(int i=0;i
一个事件-一个镜头
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
res_int, PendingIntent.FLAG_ONE_SHOT);
一个项目-一杆
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
res_int, PendingIntent.FLAG_ONE_SHOT);
添加更多关于i更改和boucle的代码。。所以值是相同的“0”?我真希望是这样。但是没有。现在尝试标记更新当前好的,更新当前给了我们一些进展。仍然不起作用,但不是onReceive中所有返回值为0的内容,而是现在所有内容都返回一个最高值iThats的值。原因:您现在发送的第一个值“0”带有FLAG_UPD