I am developing an app which perform an action on:
Is it possible that SMS failed to send. Can any one tell me how to manage the queue of failed sent SMS messages and keep retrying to send them after some time.
I have seen the code but don't know how to handle queue of SMS and resend them.
Here is Code:
private void sendSMS(String phoneNumber, String message)
{
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
//---when the SMS has been sent---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
I am not sure if I understood your question correctly but according to me, this seems a simpler solution:
When any of the above failure occurs, you can insert that number in a List, and check the list after specified time limit. If any number occurs in list, then send Msg to that number. After sending msg, you should remove that item from List
EDIT:
code-
class checkList extends AsyncTask<String, Void, Void> {
public Void doInBackground(String... p) {
while (true) {
//Check List Value Here
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
ie.printStackTrace();
Log.e("Sleep", "Error: " + ie.toString());
}
}
}
};
And in main Activity, write-
new checkList().execute();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With