在我的应用程序中,我一次发送多条短信,效果很好。但是当我试图在广播接收器中接收确认消息时,我希望得到所有数字,但我最终收到的是相同的一个数字而不是 n 个数字。
发送短信
Intent intent = new Intent(SENT);
intent.putExtra("phonenumber", sms_phonenumber);
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
SmsManager sms_man = SmsManager.getDefault();
sms_man.sendTextMessage(sms_phonenumber, null, sms_message, sentPI, null);
接收发送的确认
private class SMSReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
String phoneNumber = intent.getExtras()
.getString("phonenumber");
alertMessage("Request sent to " + phoneNumber + ".");
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
String phoneNumber1 = intent.getExtras().getString(
"phonenumber");
alertMessage("Sending Failed to " + phoneNumber1 + ".");
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
String phone = intent.getExtras().getString(
"phonenumber");
alertMessage("No service");
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
alertMessage("Null PDU");
Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT)
.show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
alertMessage("Radio off");
break;
}
}
}
我在 Google 和 SO 中进行了很多搜索,但没有一个能解决我的问题。
谢谢你的帮助。