Puedo enviar SMS automáticamente (Sin que el usuario tenga que aprobarlo)


Soy bastante nuevo en Android. Estoy tratando de enviar SMS desde la aplicación Android. Cuando se utiliza la Intent SMS, se abre la ventana SMS y el usuario debe aprobar el SMS y enviarlo.

¿Hay alguna forma de enviar automáticamente el SMS sin que el usuario lo confirme?

Gracias, Lior

Author: Saravanan, 2011-10-01

4 answers

Puede usar este método para enviar un sms. Si el sms es mayor de 160 caracteres entonces se utiliza sendMultipartTextMessage.

private void sendSms(String phonenumber,String message, boolean isBinary)
{
    SmsManager manager = SmsManager.getDefault();

    PendingIntent piSend = PendingIntent.getBroadcast(this, 0, new Intent(SMS_SENT), 0);
    PendingIntent piDelivered = PendingIntent.getBroadcast(this, 0, new Intent(SMS_DELIVERED), 0);

    if(isBinary)
    {
            byte[] data = new byte[message.length()];

            for(int index=0; index<message.length() && index < MAX_SMS_MESSAGE_LENGTH; ++index)
            {
                    data[index] = (byte)message.charAt(index);
            }

            manager.sendDataMessage(phonenumber, null, (short) SMS_PORT, data,piSend, piDelivered);
    }
    else
    {
            int length = message.length();

            if(length > MAX_SMS_MESSAGE_LENGTH)
            {
                    ArrayList<String> messagelist = manager.divideMessage(message);

                    manager.sendMultipartTextMessage(phonenumber, null, messagelist, null, null);
            }
            else
            {
                    manager.sendTextMessage(phonenumber, null, message, piSend, piDelivered);
            }
    }
}

Actualizar

PiSend y piDelivered están Pendientes Intent Pueden desencadenar una emisión cuando el método termina de enviar un SMS

Aquí está el código de muestra para el receptor de difusión

    private BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String message = null;

            switch (getResultCode()) {
            case Activity.RESULT_OK:
                message = "Message sent!";
                break;
            case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                message = "Error. Message not sent.";
                break;
            case SmsManager.RESULT_ERROR_NO_SERVICE:
                message = "Error: No service.";
                break;
            case SmsManager.RESULT_ERROR_NULL_PDU:
                message = "Error: Null PDU.";
                break;
            case SmsManager.RESULT_ERROR_RADIO_OFF:
                message = "Error: Radio off.";
                break;
            }

            AppMsg.makeText(SendMessagesWindow.this, message,
                    AppMsg.STYLE_CONFIRM).setLayoutGravity(Gravity.BOTTOM)
                    .show();
      }
  };

Y puedes registrarlo usando la siguiente línea en tu Actividad

registerReceiver(receiver, new IntentFilter(SMS_SENT));  // SMS_SENT is a constant

También no se olvide de anular el registro de difusión en onDestroy

@Override
protected void onDestroy() {
    unregisterReceiver(receiver);
    super.onDestroy();
}
 39
Author: Sunny,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-09 15:30:55

Si su aplicación tiene en el AndroidManifest.xml el siguiente permiso

<uses-permission android:name="android.permission.SEND_SMS"/>

Puedes enviar tantos SMS como quieras con

SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage(...);

Y eso es todo.

 18
Author: fampinheiro,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-10-01 12:26:06

Sí, puede enviar SMS utilizando el SmsManager. Por favor, tenga en cuenta que su aplicación necesitará el SEND_SMS permiso para que esto funcione.

 7
Author: Josef Pfleger,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-10-01 12:24:27

Sí, puede enviar sms sin hacer interacción con el usuario...Pero funciona, cuando el usuario quiere enviar sms solo a un solo número.

try {    
    SmsManager.getDefault().sendTextMessage(RecipientNumber, null,    
    "Hello SMS!", null, null);    
} catch (Exception e) {    
    AlertDialog.Builder alertDialogBuilder = new    
    AlertDialog.Builder(this);    
    AlertDialog dialog = alertDialogBuilder.create();    
    dialog.setMessage(e.getMessage());    
    dialog.show();    
}    

También, agregue permiso de manifiesto....

<uses-permission android:name="android.permission.SEND_SMS"/>
 2
Author: Nikhil,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-08 05:45:05