Answer the question
In order to leave comments, you need to log in
How to catch SMS delivery reports Android?
If I send 100 messages in a row in a cycle, then I will start receiving delivery reports. How do I know which of the recipients actually received the number and which did not?
Maybe you need to make changes to the code snippet?
public void sendSMS(String phone, String text, final String id){
String SENT="SMS_SENT";
String DELIVERED="SMS_DELIVERED";
PendingIntent sentPI= PendingIntent.getBroadcast(getBaseContext(),0,
new Intent(SENT),0);
PendingIntent deliveredPI= PendingIntent.getBroadcast(getBaseContext(),0,
new Intent(DELIVERED),0);
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1){
switch(getResultCode())
{
case Activity.RESULT_OK:
setStatus(id, "2");
Account.sent++;
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
break;
}
}
},new IntentFilter(SENT));
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1){
switch(getResultCode())
{
case Activity.RESULT_OK:{
setStatus(id, "3");
Account.get++;
//Account.list.remove(this);
break;
}
case Activity.RESULT_CANCELED:{
setStatus(id, "4");
Account.notGet++;
//Account.list.remove(this);
break;
}
}
}
},new IntentFilter(DELIVERED));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNo,null, message, sentPI, deliveredPI);
}
Answer the question
In order to leave comments, you need to log in
Perhaps this one Intent arg1
will contain a special extra with data, see the documentation, although it is unlikely. But even without this, the task is elementary, since you pass both sentPIs to sendTextMessage, then they will match, it remains only to transfer the field to the anonymous class, this is done like this:
final String num = ...;
...
registerReceiver(new BroadcastReceiver(){
...
//переменная num доступна
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question