Member-only story
Crack the OTP Code: Easy SMS Reading Techniques for Android Developers

In today’s mobile-first world, seamless user experiences are crucial, especially regarding authentication. One common method is using One-Time Passwords (OTPs) sent via SMS. But how can you read these SMS messages and extract the OTP effortlessly in your Android app?
In this blog, we’ll dive into various methods to read SMS in Android using Kotlin and show you how to implement them step-by-step.
Why Read SMS for OTP Verification?
Reading SMS messages allows you to streamline the login process by automatically retrieving the OTP sent to users. This enhances user experience by reducing manual input errors and speeding up authentication.
Method 1: Using the SMS Retriever API
The SMS Retriever API is a powerful tool provided by Google that allows you to receive SMS messages without needing SMS permissions. Let’s get started!

Step 1: Set Up Your Project
First, ensure you have the necessary dependencies in your build.gradle
file:
dependencies {
implementation 'com.google.android.gms:play-services-auth-api-phone:19.2.0'
}
Step 2: Start the SMS Retriever
In your activity, initialize the SMS Retriever:
import com.google.android.gms.auth.api.phone.SmsRetriever
fun startSmsRetriever() {
val client = SmsRetriever.getClient(this)
val task = client.startSmsRetriever()
task.addOnSuccessListener {
// SMS Retriever started successfully
}.addOnFailureListener {
// Failed to start SMS Retriever
}
}
Step 3: Create a BroadcastReceiver
Create a BroadcastReceiver
to handle incoming SMS messages. This receiver will extract the OTP for you.