Question Detail

Sending SMS programmatically without opening message app android?

4 years ago Views 1207 Visit Post Reply

How do I send SMS from the app?

How do I send text messages automatically?

How to send SMS without opening message App in android programmatically?


Thread Reply

alex levine

- 4 years ago

Manages SMS operations such as sending data, text, and pdu SMS messages. 

public static void sendSMS(Context context1, String mobileNumber) {
    contexta = context1;
    String messege = "Hi! I\'m busy, can\'t reply";
    SmsManager sms = SmsManager.getDefault();
    List<String> messages = sms.divideMessage(messege + "\nAuto-generated SMS - " + contexta.getString(R.string.app_name) + " App");
    for (String msg : messages) {
        PendingIntent sentIntent = PendingIntent.getBroadcast(contexta, 0, new Intent("SMS_SENT"), 0);
        PendingIntent deliveredIntent = PendingIntent.getBroadcast(contexta, 1, new Intent("SMS_DELIVERED"), 0);
        sms.sendTextMessage(mobileNumber, null, msg, sentIntent, null);
    }
}

 

if you want to get Message delivery report you have the change 

sms.sendTextMessage(mobileNumber, null, msg, sentIntent, null);

to

sms.sendTextMessage(mobileNumber, null, msg, sentIntent, deliveredIntent);