谁能给出一些提示,为什么这个广播接收器会收到多个意图?示例我只发送了一条短信,但广播接收器收到了多次。
我已经检查了这个线程但没有运气 从意图中获取多个广播? 多个发送消息的广播接收器?
public void sendMultipart(String msgbody, String msg_receipients, Intent intent)
{
Intent intentExtra = new Intent("SMS_SENT");
intentExtra.putExtra("phoneNumber", msg_receipients);
intentExtra.putExtra("msgbody", msgbody);
PendingIntent sentPI =
PendingIntent.getBroadcast(MyApplication.getAppContext(),
smsID++, intentExtra, PendingIntent.FLAG_CANCEL_CURRENT);
BroadcastReceiver smsStatusReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
String phoneNumber = intent.getStringExtra("phoneNumber");
String message = intent.getStringExtra("message");
int resultCode = getResultCode();
switch (resultCode)
{
case Activity.RESULT_OK:
Logger.logtoFile(tag,"RESULT_OK "+phoneNumber,1);
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Logger.logtoFile(tag,"RESULT_ERROR_GENERIC_FAILURE "+phoneNumber,1);
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Logger.logtoFile(tag,"RESULT_ERROR_NO_SERVICE "+phoneNumber,1);
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Logger.logtoFile(tag,"RESULT_ERROR_RADIO_OFF "+phoneNumber,1);
break;
}
}
};
MyApplication.getAppContext().registerReceiver(smsStatusReceiver, new IntentFilter("SMS_SENT"));
try
{
SmsManager sms = SmsManager.getDefault();
ArrayList<String> messages = sms.divideMessage(msgbody); //Divide msg into chunk
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
sentIntents.add(sentPI);
for (int j = 0; j < messages.size(); j++) {
sentIntents.add(PendingIntent.getBroadcast(MyApplication.getAppContext(),0,intent, 0));
sentIntents.add(null);
}
sms.sendMultipartTextMessage(msg_receipients, null, messages, sentIntents, null);
} catch(Exception l) {
Logger.logtoFile(tag, l.toString(), 2);
}
}