---
title: "How to send SMS in android? Explain with example."  
description: "How to send SMS in android? Explain with example."  
author: "Anonymous User"  
published: 2015-05-28  
updated: 2020-09-20  
canonical: https://www.mindstick.com/interview/2591/how-to-send-sms-in-android-explain-with-example  
category: "android"  
tags: ["android"]  
reading_time: 2 minutes  

---

# How to send SMS in android? Explain with example.

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:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_centerHorizontal="true"              android:layout_centerVertical="true"              android:onClick=”sendmySMS”              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

```
<uses-permissionandroid:name=”android.permission.SEND_SMS”/>
```

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).\

## Answers

### Answer by Anonymous User

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:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_centerHorizontal="true"              android:layout_centerVertical="true"              android:onClick=”sendmySMS”              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

```
<uses-permissionandroid:name=”android.permission.SEND_SMS”/>
```

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).\


---

Original Source: https://www.mindstick.com/interview/2591/how-to-send-sms-in-android-explain-with-example

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
