Best regards to all the problem is this:
I have this code to send text messages works perfectly but I would like to know how I can do that when a message is not sent by any problem that is presented to the application in automatic, retry sending it again about 3 times.
public class MainActivity extends Activity {
EditText txtPhone;
EditText txtMsg;
Button btnSend;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtPhone = ((EditText)findViewById(R.id.txtPhone ));
txtMsg = ((EditText)findViewById(R.id.txtMsg ));
btnSend = ((Button)findViewById(R.id.btnSend ));
btnSend.setOnClickListener(
new View.OnClickListener() {
public void onClick(View view) {
PendingIntent sentIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent("SMS_SENT"), 0);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch (getResultCode()){
case Activity.RESULT_OK:
Toast.makeText(getApplicationContext(), "SMS enviado", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getApplicationContext(), "No se pudo enviar SMS", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getApplicationContext(), "Servicio no diponible", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getApplicationContext(), "PDU (Protocol Data Unit) es NULL", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getApplicationContext(), "Failed because radio was explicitly turned off", Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter("SMS_SENT"));
SmsManager sms = SmsManager.getDefault();
if( txtPhone.getText().toString().length()> 0 &&
txtMsg.getText().toString().length()>0 )
{
sms.sendTextMessage( txtPhone.getText().toString() , null, txtMsg.getText().toString() , sentIntent, null);
}
else
{
Toast.makeText(getApplicationContext(), "No se puede enviar, los datos son incorrectos", Toast.LENGTH_SHORT).show();
}
}});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}