Home > DeveloperSection > Interviews > How to send SMS in android? Explain with example.

Posted on    May-28-2015 11:53 PM

 Android Android 
 1 Answer(s)
  478  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Posted on    May-28-2015 11:53 PM

If you want to send the SMS programmatically then follow the following steps.

Take a button on activity_main.xml file as follows.

<Button android:id="@+id/btnSendSMS" 
             android:text="sendSMS" />

According to above code when user clicks the button sendmySMS method will be called. sendmySMS is user defined method.

In the AndroidManifest.xml file, add the following statements


Now we write the final step. Write the given below method in MainActivity,java file

publicvoidsendmySMS(View v)
SmsManager sms = SmsManager.getDefault(); 
sms.sendTextMessage("5556", null, "Hello from MindStick", null, null);

In this example we have used two emulator. On the first Android emulator (5544), click the Send SMSbutton to send an SMS message to the second emulator(5546).

Modified On May-28-2015 11:55:32 PM

Don't want to miss updates? Please click the below button!

Follow MindStick