Use a thread, I did it and I do not bother that message anymore
In my case I managed to work send 10 and pause 20 seconds
Thread thread = new Thread() {
public void run() {
try {
int contador = 0;
int contAux = 0;
while (datos.next()) {
int total = datos.getInt(5);
if (ActivityCompat.checkSelfPermission(MensajeAbonados.this, Manifest.permission.SEND_SMS) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MensajeAbonados.this, new String[]{Manifest.permission.SEND_SMS}, PERMISSION_SEND_SMS);
} else {
//do send or read sms
String strPhone = datos.getString(1);
SmsManager sms = SmsManager.getDefault();
String mensaje = txtMensaje.getText().toString();
sms.sendTextMessage("+52"+strPhone, null, mensaje, null, null);
contador++;
contAux++;
toastContador("Enviados " + contador + " de " + total);
if (contAux == 10 ) {//NUmero de mensajes para iniciar pausa
contAux = 0;
Thread.sleep(20000);
}
}
}
if(contador > 0)
progress(pd, "Se enviaron " + contador + " mensajes.");
else
progress(pd, "No hay mensajes para enviar.");
conn.close();
} catch (SQLException se) {
Log.e("SQLError", se.getMessage());
} catch (Exception e) {
Log.e("Exception error", e.getMessage());
}
}
};
thread.start();