SoulRayder SoulRayder - 1 year ago 168
Android Question

Sending SMS programmatically without opening message app

So far I am using the following code to send SMS to another phone through my app.

Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + srcNumber));
intent.putExtra( "sms_body", message );

However, this opens up the native messaging app, thereby putting my app's activity in the background. Is it possible to send the SMS directly without the native messaging app opening up? If yes, how?

Answer Source

You can send message from your application throug this:

public void sendSMS(String phoneNo, String msg) {
    try {      
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(phoneNo, null, msg, null, null);    
        Toast.makeText(getApplicationContext(), "Message Sent",
    } catch (Exception ex) {

Also you need to give SEND_SMS permission in AndroidManifest.xml to send message

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download