Create SMS Android App Using Android Studio

Introduction

In this article, I will show you how to create an SMS Android App using Android Studio. SMS stands for Short Message Service and is also commonly referred to as a "text message". With an SMS app, you can send a message of up to 160 characters to another device. Longer messages will automatically be split into several parts. Most cell phones support this type of text messaging.

Requirements

Steps to be followed

Follow these steps to create an SMS app using Android Studio. I have attached the source code too.

Step 1

Open Android Studio and start a new Android Studio Project.

Android 

Step 2

You can choose your application name and choose the location where your project is stored. If you wish to use C++ for coding the project, mark the "Include C++ support", and click "Next" button.

Android

Step 3

Now, select the version of Android and select the target Android devices. We need to choose the SDK level which plays an important role in running the application.

Android

Step 4

Now, add the activity and click "Next" button.

Android

Step 5

Add Activity name and click "Finish".

Android

Step 6

Go to activity_main.xml. This XML file contains the designing code for your Android app.

Android

The XML code is given below.

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >

    <EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="20dp"
    android:ems="10" />

    <EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText1"
    android:layout_below="@+id/editText1"
    android:layout_marginTop="26dp"
    android:ems="10"
    android:inputType="textMultiLine" />

    <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/editText1"
    android:layout_alignBottom="@+id/editText1"
    android:layout_toLeftOf="@+id/editText1"
    android:text="Mobile No:" />

    <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/editText2"
    android:layout_alignBottom="@+id/editText2"
    android:layout_alignLeft="@+id/textView1"
    android:text="Message:" />

    <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText2"
    android:layout_below="@+id/editText2"
    android:layout_marginLeft="34dp"
    android:layout_marginTop="48dp"
    android:text="Send SMS" />

    </RelativeLayout>

Step 7

Go to  Main Activity.java. This Java program is the backend language for Android.

Android

The java code is given below.

  1. package abu.sms;  
  2.   
  3. import android.os.Bundle;  
  4. import android.app.Activity;  
  5. import android.app.PendingIntent;  
  6. import android.content.Intent;  
  7. import android.telephony.SmsManager;  
  8. import android.view.Menu;  
  9. import android.view.View;  
  10. import android.view.View.OnClickListener;  
  11. import android.widget.Button;  
  12. import android.widget.EditText;  
  13. import android.widget.Toast;  
  14.   
  15. public class MainActivity extends Activity {  
  16.   
  17.     EditText mobileno,message;  
  18.     Button sendsms;  
  19.     @Override  
  20.     protected void onCreate(Bundle savedInstanceState) {  
  21.         super.onCreate(savedInstanceState);  
  22.         setContentView(R.layout.activity_main);  
  23.   
  24.         mobileno=(EditText)findViewById(R.id.editText1);  
  25.         message=(EditText)findViewById(R.id.editText2);  
  26.         sendsms=(Button)findViewById(R.id.button1);  
  27.         sendsms.setOnClickListener(new OnClickListener() {  
  28.   
  29.             @Override  
  30.             public void onClick(View arg0) {  
  31.                 String no=mobileno.getText().toString();  
  32.                 String msg=message.getText().toString();  
  33.                 Intent intent=new Intent(getApplicationContext(),MainActivity.class);  
  34.                 PendingIntent pi=PendingIntent.getActivity(getApplicationContext(), 0, intent,0);  
  35.                 SmsManager sms=SmsManager.getDefault();  
  36.                 sms.sendTextMessage(no, null, msg, pi,null);  
  37.   
  38.                 Toast.makeText(getApplicationContext(), "Message Sent successfully!",  
  39.                         Toast.LENGTH_LONG).show();  
  40.             }  
  41.         });  
  42.     }  
  43.   
  44.     @Override  
  45.     public boolean onCreateOptionsMenu(Menu menu)   
  46.        getMenuInflater().inflate(R.menu.activity_main, menu);  
  47.         return true;  
  48.     }  
  49.   
  50. }   

Step 8

 We need to make Sender and Receiver requests. So, add Bluetooth permissions in an AndroidManifest.xml.

Android

The AndroidManifest.xml code is given below.

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="abu.sms">  
  4.     <uses-permission android:name="android.permission.SEND_SMS"/>  
  5.     <uses-permission android:name="android.permission.RECEIVE_SMS"/>  
  6.   
  7.     <application  
  8.         android:allowBackup="true"  
  9.         android:icon="@mipmap/ic_launcher"  
  10.         android:label="@string/app_name"  
  11.         android:roundIcon="@mipmap/ic_launcher_round"  
  12.         android:supportsRtl="true"  
  13.         android:theme="@style/AppTheme">  
  14.         <activity android:name=".MainActivity">  
  15.             <intent-filter>  
  16.                 <action android:name="android.intent.action.MAIN" />  
  17.   
  18.                 <category android:name="android.intent.category.LAUNCHER" />  
  19.             </intent-filter>  
  20.         </activity>  
  21.     </application>  
  22.   
  23. </manifest>  

Step 9

Now, go to the menu bar and click "Make Project" option or press ctrl+f9 to debug the error.

Android

Step 10

Then, click "Run" button or press shift+f10 to run the project. And, choose the "virtual machine" option and click OK.

Android

Conclusion

We have successfully created an SMS Android application using Android Studio. Here is the output.

Android

Android

Up Next
    Ebook Download
    View all
    Learn
    View all