android sendTextMessage发送多条短信,广播接收到相同内容
我使用 SmsManager.getDefault()去发送多条短信(通过for循环去发送),并在intent中put相关信息,通过接收广播,判断是否发送成功。广播接收到后,从intent中获取到的信息只是第一条的发送内容,后面所有都重复第一条的内容,求高手帮助解答,急啊~~~~
短信发送代码
for(int i=3;i<5;i++){
sendSms("code"+i,"1391840160"+i,i+"sms content is test,i hope success!");
}
public void sendSms(String code,String comPhone,String content) {
sentIntent.putExtra("SEND_SMS_NUM", comPhone);
sentIntent.putExtra("SEND_SMS_CONTENT", content);
sentIntent.putExtra("SEND_SMS_CODE", code);
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent,0);
Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION);
PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0,deliverIntent, 0);
Log.w(TAG, "扣费短信编码为----->存储【"+sentIntent.getStringExtra("SEND_SMS_CODE")+"】");
Log.w(TAG, "发送短信--接收手机号码为------>存储【" + sentIntent.getStringExtra("SEND_SMS_NUM") + "】");
Log.w(TAG, "发送短信内容为------>存储【" + sentIntent.getStringExtra("SEND_SMS_CONTENT")+"】");
sms.sendTextMessage(comPhone, null, content, sentPI, deliverPI);
}
广播接收代码
BroadcastReceiver receiver=new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Log.i(TAG, "短信发送成功!------>编号=【"+intent.getStringExtra("SEND_SMS_CODE")+"】<------>号码=【"+intent.getStringExtra("SEND_SMS_NUM")+"】<------>内容=【"+intent.getStringExtra("SEND_SMS_CONTENT")+"】");
break;
default:
Log.i(TAG, "短信发送成功!------>编号=【"+intent.getStringExtra("SEND_SMS_CODE")+"】<------>号码=【"+intent.getStringExtra("SEND_SMS_NUM")+"】<------>内容=【"+intent.getStringExtra("SEND_SMS_CONTENT")+"】");
break;
}
}
};
IntentFilter filter=new IntentFilter();
filter.addAction(SENT_SMS_ACTION);
filter.addAction(DELIVERED_SMS_ACTION);
filter.addAction(SMS_RECEIVED);
filter.addCategory(DEFAULT);
filter.setPriority(priority);
this.registerReceiver(receiver, filter);
具体接收的情况
06-21 11:18:55.875: W/MainActivity(19388): 扣费短信编码为----->存储【code3】
06-21 11:18:55.875: W/MainActivity(19388): 发送短信--接收手机号码为------>存储【13918401603】
06-21 11:18:55.875: W/MainActivity(19388): 发送短信内容为------>存储【3sms content is test,i hope success!】
06-21 11:18:55.925: I/MainActivity(19388): 短信发送成功!------>编号=【code3】<------>号码=【13918401603】<------>内容=【3sms content is test,i hope success!】
06-21 11:18:55.925: I/MainActivity(19388): 短信发送完成!
06-21 11:19:01.931: W/MainActivity(19388): 扣费短信编码为----->存储【code4】
06-21 11:19:01.931: W/MainActivity(19388): 发送短信--接收手机号码为------>存储【13918401604】
06-21 11:19:01.931: W/MainActivity(19388): 发送短信内容为------>存储【4sms content is test,i hope success!】
06-21 11:19:01.931: D/Jerry(19388): getSystemPreference msgId >1
06-21 11:19:01.941: I/MainActivity(19388): action name is------>SENT_SMS_ACTION
06-21 11:19:01.941: I/MainActivity(19388): 短信发送成功!------>编号=【code3】<------>号码=【13918401603】<------>内容=【3sms content is test,i hope success!】
06-21 11:19:01.941: I/MainActivity(19388): 短信发送完成!
接收到的短信内容都是相同的,不知道为什么,求高人指导~~~万分感谢