I everybody, sorry for bad english, google is my friend... ;-)
I am developing an application which sends an SMS to a recipient when a button is pressed (several buttons, several recipients ...), when an SMS is not sent, I am able to catch the error (RESULT_ERROR_GENERIC_FAILURE , RESULT_ERROR_NO_SERVICE, RESULT_ERROR_NULL_PDU, RESULT_ERROR_RADIO_OFF, etc.). I would like to know the specific SMS that was not sent ...
Example : I want to tell "SMS to 111-222-3333 was not sent"...
Thanks a lot !
Patrick
This is how i send SMS:
public void sendSmsByManager(String noTelephone, String message ) {
try {
// Get the default instance of the SmsManager
SmsManager smsManager = SmsManager.getDefault();
//réponse pour sms envoyé
PendingIntent piSent=PendingIntent.getBroadcast(this, 0, new Intent("SMS_SENT"), 0);
//réponse pour sms reçu
PendingIntent piDelivered=PendingIntent.getBroadcast(this, 0, new Intent("SMS_DELIVERED"), 0);
//envoi
smsManager.sendTextMessage(noTelephone,
null,
message,
piSent,
piDelivered);
//Toast.makeText(getApplicationContext(), "Message envoyé !", Toast.LENGTH_LONG).show();
} catch (Exception ex) {
Toast.makeText(getApplicationContext(),"Erreur lors de l'envoi du message texte ! Vérifiez les permissions de l'application...",Toast.LENGTH_LONG).show();
ex.printStackTrace();
}
}
This is how i catch the error:
public void onResume() {
super.onResume();
smsSentReceiver=new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "Le message texte a été envoyé", 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(), "Erreur: Pas de service", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Erreur: Null PDU", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio Off", Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
};
smsDeliveredReceiver=new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
switch(getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "Le message texte a été envoyé", Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "Le message texte n'a pas été envoyé", Toast.LENGTH_LONG).show();
break;
}
}
};
registerReceiver(smsSentReceiver, new IntentFilter("SMS_SENT"));
registerReceiver(smsDeliveredReceiver, new IntentFilter("SMS_DELIVERED"));
}