SmsManager in Android using Jetpack Compose
Many times while building an android application we have to add a feature through which users will be able to directly send SMS from our android application. So in this article, we will take a look at How to send a text message over a phone using SMS Manager in Android using Jetpack Compose. A sample video is given below to get an idea about what we are going to do in this article.
Step by Step Implementation
Step 1: Create a New Project in Android Studio
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. While choosing the template, select Empty Compose Activity. If you do not find this template, try upgrading the Android Studio to the latest version. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project.
Step 2: Adding a new color to the Color.kt file
Navigate to app > java > your app’s package name > ui.theme > Color.kt file and add the below code to it.
Step 3: Working with the MainActivity.kt file
Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.
Step 4: Adding permissions in AndroidManifest.xml
Navigate to AndroidManifest.xml and add the below permission to it for sending SMS.
Now run your application to see the output of it.
Note: We are sending SMS to a sample phone number and that’s why it is displaying as failed in the SMS application. If we enter the actual number to whom we have to send SMS it will be sent to that number.
Please Login to comment...