Android Kotlin Project – SMS App

Hello there, Android enthusiasts! Today, we will look at and learn how to develop an Android project that is an SMS app in Android Studio. In this article, we’ll learn about the entire project’s development.

The SMS application will enable the user to text other phones or devices from their own phone number. You can learn how to create Android apps using Kotlin and how to use different permissions to add functionality to the app while developing applications in Android Studio. In this case, the ‘SEND_SMS’ permission will enable our application to send text messages.

About Android Kotlin SMS App

This is a simple SMS App project for those just learning the fundamentals of developing Android applications. This Android app’s user interface contains two text fields for the user to enter the phone number and the text message they wish to send. To develop this SMS application, we will work with Android Studio and Kotlin. Below is a list of the functionalities that the user interface will have:

1. When the application is initialized, the user needs to give permission to the application to view and send text messages by clicking ‘Allow’.
2. The user interface contains a text field where the user is required to enter the phone number on which they want to send the text message.
3. The user interface contains another text field where the user is required to enter the text message they want to send via the SMS application.
4. The user interface will also contain a button ‘Send SMS’ below the two text fields. When the button is clicked, the entered text message by the user will be sent to the number entered by the user.

Prerequisites for SMS App using Android Kotlin

To develop this SMS Android application, the requirements and prerequisites are as follows:

1. Kotlin: You must become acquainted with Kotlin programming first. It is necessary because we’ll be writing the app’s code in the programming language Kotlin.
2. XML: XML is a further essential part of our Android application. It will be used to create the user interface for the application.
3. Android Studio: Android Studio is at the core of our application because it is how we will create it. An Android virtual device that can be used to test an application’s functionality is also available with Android Studio.

Download Android Kotlin SMS App Project

Please download the source code of Android Kotlin SMS App Project from the following link: Android Kotlin SMS App Project Code.

Steps to Create an SMS App Project Using Android Kotlin

We’ll now start working on developing an SMS app. Before actually implementing and executing the code, we will learn about its working. So, let’s look at the files and functions needed to run the code:

In order to make this Android Kotlin SMS application, you must follow a set of instructions. We are here to guide you through each step of creating an app.

1. To the location of your choice, extract all the files from the downloaded zip file.
2. Launch Android Studio.
3. Open by selecting File.
4. Locate and choose the extracted folder, then select OK.

The SMS app’s source code has been successfully opened in Android Studio.

sms app android studio

Before getting started with the ‘MainActivity.kt’ and ‘acitivity_main.xml’ files, we need to set up some things in the ‘AndroidManifest.xml’ file.

1. To be able to send SMS via our application, we need to add uses-permission in the ‘AndroidManifest.xml’ file. Add the following line of code to the file:

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

androidmanifest

2. The “activity_main” is an XML file that is responsible for creating the user interface of the home screen that is displayed when the SMS app is initialized.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:padding="15sp"
    tools:context=".MainActivity">

    <EditText
        android:background="@android:drawable/editbox_background"
        android:inputType="phone"
        android:maxLength="10"
        android:id="@+id/editTextPhone"
        android:padding="15sp"
        android:hint="Enter Phone Number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/editTextMessage"
        android:padding="15sp"
        android:layout_marginTop="20dp"
        android:inputType="textMultiLine"
        android:hint="Enter Text Message"
        android:background="@android:drawable/editbox_background"
        />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnSent"
        android:text="Send SMS"
        android:textAllCaps="false"
        android:layout_marginTop="30sp"/>
</LinearLayout>

sms app activity main

3. ‘MainActivity’ is a kotlin file responsible for the functionality of the SMS application. checkPermissions and sendSMS are the two functions defined in this file that are responsible for requesting permission to view and send messages and send text messages, respectively.

Code:

class MainActivity : AppCompatActivity() {

    private lateinit var phone: EditText
    private lateinit var messageEdit: EditText
    private lateinit var sendBtn: Button
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)


        phone = findViewById(R.id.editTextPhone)
        messageEdit = findViewById(R.id.editTextMessage)
        sendBtn = findViewById(R.id.btnSent)

        checkPermissions()

        sendBtn.setOnClickListener {
            sendSMS();
        }
    }

    private fun sendSMS() {
        var phoneNo: String = phone.text.toString()
        var message: String = messageEdit.text.toString()

        if(phoneNo.isNotEmpty() && message.isNotEmpty()){
            val smsManager = SmsManager.getDefault()
            smsManager.sendTextMessage(phoneNo, null, message,null,null)
            Toast.makeText(this,"Text message has been delivered", Toast.LENGTH_SHORT).show()
            phone.text.clear()
            messageEdit.text.clear()
        }
    }

    private fun checkPermissions() {
        if(ActivityCompat.checkSelfPermission(this, android.Manifest.permission.SEND_SMS) != PackageManager.PERMISSION_GRANTED){
            ActivityCompat.requestPermissions(this, arrayOf(android.Manifest.permission.SEND_SMS),101)
        }
    }
}

Android Kotlin SMS App Output

1. Requesting Permission when the app is initialized:

sms app requesting permsission

2. Home Screen:

sms app home screen

3. Enter Details:

sms app enter details

4. Confirmation after ‘Send SMS’ is clicked:

sms app confirmation

5. Text Message Sent:

sms app text message sent

Summary

So, in this Android Kotlin SMS App Project, we learned how to use Android Studio to develop an SMS application. This Android project is suitable for beginners as it will improve your ability to design user interfaces as per the application’s need and use various permissions in the manifest to add functionalities to the Android application. We hope you enjoyed it, and we are confident that you will like putting it into practice.

Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *