android restricts bulk SMS sending

0

Hello community of programmers, I'm making a mass-sent SMS app in the background, but apparently Android limits the sending, for example: I need to send 50 sms, the first 30 are sent, then a notification appears on the screen to authorize (manually) the sending of each of the remaining 20 sms. I'm not sure if it depends on the device, the operating system or what I fear the most "mobile phone provider".

    
asked by Romel Hammerlin Diaz Ramos 08.07.2018 в 07:52
source

1 answer

0

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();
    
answered by 09.08.2018 в 00:15