
How to Send SMS in Android ?
In this Tutorial using SMS Manager to Send SMS in Android application. In this SMS Directly Send SMS On your Android Application.
You can Use Intent with proper action (ACTION_VIEW), it will invoke built-in SMS app to send SMS from our application.
In Android Provide to Built in SMSManager api to send the message in other device or person from directly on your application.
Android Device can send and receive messages to or from any other phone that supports Short Message Service (SMS).
You have two choices for sending SMS messages: Use an implicit Intent to launch a messaging app with the ACTION_SEND TO intent action. In this Choice is simple choice to send SMS.
Send SMS to Give Permission in Sending SMS to allow Runtime And Input Number And Message to Send SMS. Sending SMS is use to SMSManager provide to send SMS to enter number to sending SMS.
Example of Send SMS in Android
Declared Permission in AndroidManifest.xml File.
1 2 |
<uses-permission android:name="android.permission.SEND_SMS" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> |
Create activity_main.xml File Follow this Code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:layout_marginTop="20dp" android:layout_gravity="center_horizontal" android:hint="Enter Mobile No" android:inputType="phone" android:imeOptions="actionNext" android:maxLength="10" android:id="@+id/et_mobile"/> <EditText android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:layout_marginTop="20dp" android:layout_gravity="center_horizontal" android:hint="Enter Your Message" android:gravity="top" android:imeOptions="actionDone" android:id="@+id/et_message"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:layout_gravity="center_horizontal" android:text="Send" android:id="@+id/btn_send"/> </LinearLayout> |
Create MainActivity.java File Follow this Code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
package com.example.bhaumik.sendsms; import android.app.PendingIntent; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends AppCompatActivity { EditText et_mobile,et_message; Button btn_send; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et_mobile = findViewById(R.id.et_mobile); et_message = findViewById(R.id.et_message); btn_send = findViewById(R.id.btn_send); btn_send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(); PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,1,intent,0); SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(et_mobile.getText().toString(),null,et_message.getText().toString(),pendingIntent,null); Toast.makeText(MainActivity.this, "Message Sent Successfully...", Toast.LENGTH_SHORT).show(); } }); } } |

Above the Example of Create Simple Send SMS in Android.I have Create Simple EditText to Enter Mobile No And then Type the Message And Create Simple Button to Send The SMS to Entered the Mobile No.