我试图捕捉每个短信传递的状态,但我的代码没有得到它,而是只有一条消息的状态。
任何人都可以提供提示吗?这是我的代码.. 这是有效的,但我需要捕捉每个短信的每个状态。
public void sendMultipart(String msgbody,String msg_receipients,Intent intent)
{
BroadcastReceiver smsStatusReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
context.unregisterReceiver(this); //unregister receiver
switch (getResultCode())
{
case Activity.RESULT_OK:
Logger.logtoFile(tag,"RESULT_OK "+intent.getStringExtra("num"),1);
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Logger.logtoFile(tag,"RESULT_ERROR_GENERIC_FAILURE "+intent.getStringExtra("num"),1);
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Logger.logtoFile(tag,"RESULT_ERROR_NO_SERVICE "+intent.getStringExtra("num"),1);
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Logger.logtoFile(tag,"RESULT_ERROR_RADIO_OFF "+intent.getStringExtra("num"),1);
break;
}
}
};
IntentFilter intentFilter = new IntentFilter("sent");
MyApplication.getAppContext().registerReceiver(smsStatusReceiver, intentFilter);
Intent intent1 = new Intent("sent");
intent1.putExtra("num", msg_receipients);
SmsManager sms = SmsManager.getDefault();
try
{
ArrayList<String> messages = sms.divideMessage(msgbody); //Divide msg into chunk
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>(messages.size());
for (int j = 0; j < messages.size(); j++)
sentIntents.add(PendingIntent.getBroadcast(MyApplication.getAppContext(), 0, intent1, 0));
sms.sendMultipartTextMessage(msg_receipients, null, messages, sentIntents, null);
}catch(IllegalArgumentException e)
{Logger.logtoFile(tag, "SMS sender error "+e.toString(), 2);}
catch(Exception l)
{Logger.logtoFile(tag, l.toString(), 2);}
}