Android tutorial: Send SMS programatically

SmsManager has a method that is sending SMS message completely without user’s interaction needed. If You need to send SMS from your code:

1. Use SmsManager

Add these lines to your app

import android.telephony.SmsManager;

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("123456789", null, "sms message", null, null);

You can replace these nulls with Intents (according to documentation) that will be fired up when SMS is delivered / sent / failed to send. In basic case it is optional and can be null.

2. request permissions in AndroidManifest.xml

Add these lines to Manifest:

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

Remember

Remember to have active SIM card in your device when you want to send SMS :)

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!

9 thoughts on “Android tutorial: Send SMS programatically

  1. hello
    what is the need of having working sim card while we are sending message by application.

    Reply I am waiting

    1. and how are you going to send SMS otherwise?…

      Of course the code will work withot SIM card inserted but SMS obviously will not be sent

      1. what i want is, user will insert his/her number, and my app should get the no and send sms to the same number so that we can get back this number from the user to verify . means app should send verification code via sms not user, still require the working sim?

      2. yes. you need SIM card to send sms. even to yourself – it involves the cellular network.

        what’s more… rethink your application flow and logic. Such logic seems irrational to me

  2. Thanks alot Mr. Jacek i got solved issue means now i am able to send sms. but still wat i want that when i prompt user to send msg on their number for verification purpuse the name of the sender should be the “App Name” not the user’s number. currently the name of the sender is user’s own number.
    Do you have any Idea about this please help I am waiting for your response.

    Thanks

    1. It’s possible by adding the number to the address book, so it will appear with the desired name

      such sender modification is doable only by Network operators. You cannot modify it afaik

Give Your feedback: