Android 17 Withholds OTP SMS for 3 Hours: SMS Retriever Migration
Android 17 withholds OTP SMS from most apps for 3 hours. Migrate your app to the SMS Retriever and User Consent APIs, with Kotlin code and server hash setup.
Meera leads the Android team at a Pune lending app with 1.4 million installs. In October she flashed the Android 17 beta onto a Pixel, opened her own app, requested a login code, and watched the OTP field stay empty. The SMS arrived in the Messages app within four seconds. Her app, which had read OTPs automatically for three years, never saw it. She assumed a broken build. It was not a build. It was the single biggest Android 17 OTP SMS change in a decade, and it will hit every Indian app that still reads codes straight from the inbox.
This tutorial explains exactly what Android 17 withholds and for how long, which apps are affected, how to migrate to the SMS Retriever API and the SMS User Consent API with working Kotlin, and what has to change on the server so the message you send through the StartMessaging OTP API (₹0.25 per OTP, no DLT registration required) is one Android will hand to your app. Meera’s team shipped the migration in four working days. Here is the path they took, including the one decision about DLT templates that decides which API you can use.
What Android 17 Actually Changes for OTP SMS
Android 17 is one of nine 2027 shifts for OTP pipelines; the SMS OTP in India 2027 hub has the full calendar.
Android 17 (API level 37) adds a behaviour change that Google documents under “SMS OTP protection”. When a standard-format one-time code arrives by SMS, the system withholds that message from most apps for three hours after receipt. Two things happen during that window. The SMS_RECEIVED broadcast is not delivered to apps other than the default SMS app and designated companion apps. And queries against the SMS content provider (content://sms) filter the message out, so an app that polls the inbox looking for a six-digit code finds nothing.
After three hours the message becomes visible through both paths. By then the OTP has expired, so for login flows the practical effect is permanent: the inbox-reading approach is dead on Android 17.
Google’s reasoning is straightforward. OTP-stealing malware has been the single most common Android banking threat in India for years. An app that holds READ_SMS or RECEIVE_SMS can lift a code the moment it lands, and the platform cannot tell a legitimate lending app from a trojan that asked for the same permission. Withholding the message for three hours removes the value of the permission entirely. Google Play policy already restricted those permissions to default SMS and backup apps in 2019; Android 17 enforces it at the operating system.
| Behaviour | Android 16 and earlier | Android 17 |
|---|---|---|
SMS_RECEIVED broadcast for an OTP-format SMS | Delivered to any app holding RECEIVE_SMS | Withheld for 3 hours from non-default apps |
Query content://sms for a fresh OTP | Returns the message | Message filtered out for 3 hours |
| Default SMS app | Full access | Full access |
| Companion device apps (watches, Auto) | Full access | Full access |
| SMS Retriever API (hash in message) | Works, no permission | Works, no permission |
| SMS User Consent API (one-time prompt) | Works, no permission | Works, no permission |
“Standard-format” matters. The detection is heuristic: a short message containing a 4 to 8 digit code and the usual wording. Every OTP StartMessaging delivers through its pre-approved templates matches that pattern, which is the point. Do not try to write a template that dodges the detector. Operators flag odd OTP wording, and you would be fighting the platform instead of using the two APIs it built for this.
Who Is Affected, and Who Is Not
Meera’s app was affected because it had been grandfathered. It shipped before the 2019 Play policy, kept RECEIVE_SMS through a permissions declaration form, and never moved. If your app does any of the following, Android 17 breaks your autofill:
- Declares
RECEIVE_SMSorREAD_SMSand parses the code from the broadcast. - Polls
content://smsafter calling the send endpoint. - Uses a third-party “auto OTP” library that wraps one of the above.
If your app already uses the SMS Retriever API or the SMS User Consent API, nothing changes. Both APIs are provided by Google Play services, both work without any SMS permission, and Android 17 explicitly exempts them because the user, or the message itself, grants the access.
React Native and Flutter apps are affected in the same way; the platform behaviour sits below the framework. The fix is the same two APIs, reached through a native module or a plugin that wraps them. The server-side changes described below apply to every stack, which is why the backend rules from our mobile OTP backend guide still hold: the client never calls the SMS gateway directly.
One more group is affected without knowing it: apps that read the OTP from the notification shade using a NotificationListenerService. That path depends on the default SMS app posting a notification, which it still does on Android 17, but Play policy treats notification scraping of OTPs the same way it treats READ_SMS. Do not migrate to it.
How the SMS Retriever API Works
The SMS Retriever API lets your app receive exactly one SMS, the one addressed to it, without any permission and without the user doing anything. The trick is in the message. The SMS must be no longer than 140 bytes, must contain the one-time code, and must end with an 11-character hash that identifies your app. Google Play services sees the hash, matches it against the app that called startSmsRetriever(), and hands that app the full message body. No other app gets it, and the user never sees a permission prompt.
Older guides show a <#> prefix at the start of the message. Current Google documentation no longer requires it; only the trailing hash matters. Keep the prefix out, it wastes bytes and confuses DLT template reviewers.
The hash is derived from your package name and your signing certificate, so it is stable for a given build but different between debug, upload and Play App Signing keys. Compute it once per signing key:
# Export the signing cert, hex-encode it, hash it with the package name, take 11 chars
keytool -exportcert -alias upload -keystore release.keystore | xxd -p | tr -d "[:space:]" > cert.hex
echo -n "in.meerapay.app " | cat - cert.hex | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11
The output looks like FA+9qCX9VSu. Store it as a server-side config value per build variant. Google also publishes an AppSignatureHelper class that computes the same value at runtime on the device; use it during development to confirm the value, never in production, because the server has to know the hash before the SMS is sent.
A message that satisfies the Retriever looks like this:
483921 is your MeeraPay login code. Valid 5 minutes. FA+9qCX9VSu
That is 71 bytes in GSM-7, well under the limit, and matches the “standard OTP format” that Android 17 withholds from everyone except the app whose hash it carries.
The Server Side: Getting the Hash Into the Message
This is where Indian apps have to make a decision, because the hash has to be inside the SMS body, and who controls the body depends on how you send.
StartMessaging offers two routes for OTP SMS in India. The DLT-free route sends through StartMessaging’s own pre-approved DLT templates. You post the phone number and the code, and the message text is StartMessaging’s. That route exists so that a startup can send its first OTP in five minutes with no entity registration, no header, and no template approval. The cost of that convenience is that the template text is fixed. You cannot append your app hash to it, so the SMS Retriever API cannot match it. On that route, use the SMS User Consent API described below; it needs nothing special in the message.
The second route is your own DLT template. If your business already holds a Principal Entity ID and a registered header, you register a template whose text ends with a variable, and pass the hash as that variable on every send. StartMessaging’s send endpoint accepts a templateId for DLT routes and a variables object that carries the OTP plus any custom placeholders your template defines.
Register the template text with the hash slot at the end:
{#var#} is your MeeraPay login code. Valid 5 minutes. {#var#}
Then send through the API. The request below is a plain HTTP call from your backend; no client library is needed:
curl -X POST https://api.startmessaging.com/otp/send \
-H "X-API-Key: sm_live_xxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"phoneNumber": "+919876543210",
"templateId": "1107161234567890123",
"variables": {
"otp": "483921",
"appHash": "FA+9qCX9VSu"
},
"idempotencyKey": "login-7f3a8c-20261106-1"
}'
Your backend generates the six-digit code, stores its hash with an expiry, and sends it in variables.otp. The second placeholder carries the app hash; name it the way you named it when the template was set up in your StartMessaging dashboard, and confirm the placeholder names there before you ship. The idempotencyKey stops a retried request from sending a second SMS, which matters more than usual here because a duplicate message with the same hash confuses the Retriever on the device.
Three details decide whether the DLT reviewer approves the template. The hash variable is a free-text variable, and under the 2026 variable tagging rules it should be tagged as alphanumeric with a maximum length of 11. The whole message, with a six-digit code and the hash filled in, must stay under 140 bytes; count it after substitution, not before. And the text must still read as a transactional OTP, because the same wording also has to pass Android’s “standard format” detection. Our DLT template variable rules post covers the tagging in detail.
Verification does not change at all. When the user submits the code, your backend calls POST /otp/verify with the otpRequestId from the send response and the code the user typed. The platform APIs on the phone only change how the code gets into the text field.
Client Implementation in Kotlin
The client flow has three steps: start the Retriever before you request the OTP, register a receiver for the single broadcast Play services will send, and parse the code out of the message. The order matters. If you call the send endpoint first and the SMS arrives before the Retriever is listening, the message is lost to your app and the user types it by hand.
Add the dependency:
// build.gradle.kts (app)
dependencies {
implementation("com.google.android.gms:play-services-auth-api-phone:18.1.0")
}
Start the Retriever, then call your backend:
// LoginViewModel.kt
import com.google.android.gms.auth.api.phone.SmsRetriever
fun requestOtp(context: Context, phone: String) {
val client = SmsRetriever.getClient(context)
client.startSmsRetriever()
.addOnSuccessListener {
// Listening for up to 5 minutes. Only now ask the backend to send.
viewModelScope.launch { api.sendOtp(phone) }
}
.addOnFailureListener { e ->
// Play services unavailable or outdated: fall back to manual entry
Log.w("Otp", "SMS Retriever unavailable: ${e.message}")
viewModelScope.launch { api.sendOtp(phone) }
}
}
Receive the message. On Android 13 and later the receiver must be registered with the SEND_PERMISSION constant so that only Play services can trigger it:
// OtpSmsReceiver.kt
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import androidx.core.content.ContextCompat
import com.google.android.gms.auth.api.phone.SmsRetriever
import com.google.android.gms.common.api.CommonStatusCodes
import com.google.android.gms.common.api.Status
class OtpSmsReceiver(private val onCode: (String) -> Unit) : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action != SmsRetriever.SMS_RETRIEVED_ACTION) return
val extras = intent.extras ?: return
val status = extras.get(SmsRetriever.EXTRA_STATUS) as? Status ?: return
when (status.statusCode) {
CommonStatusCodes.SUCCESS -> {
val body = extras.getString(SmsRetriever.EXTRA_SMS_MESSAGE) ?: return
// First 4 to 8 digit run is the code. Keep the regex strict.
Regex("""\b(\d{4,8})\b""").find(body)?.groupValues?.get(1)?.let(onCode)
}
CommonStatusCodes.TIMEOUT -> {
// 5 minutes passed with no matching SMS. Leave the field editable.
}
}
}
companion object {
fun register(context: Context, receiver: OtpSmsReceiver) {
ContextCompat.registerReceiver(
context,
receiver,
IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION),
SmsRetriever.SEND_PERMISSION,
null,
ContextCompat.RECEIVER_EXPORTED
)
}
}
}
Register the receiver when the OTP screen appears and unregister when it leaves. In an Activity that is onStart and onStop; in Jetpack Compose use a DisposableEffect keyed on the screen, as shown in our Compose OTP tutorial. The Ktor and Retrofit client code for the send and verify calls is unchanged from the Kotlin OTP guide; only the Retriever wiring is new.
Two mistakes show up in almost every first implementation. The first is starting the Retriever after the network call returns, which loses the race on fast networks like Jio in a metro. The second is a greedy regex that picks up a number from the brand name or the expiry (“Valid 5 minutes” is not the code). Anchor the pattern to word boundaries and prefer the first match.
Fallback: The SMS User Consent API
The User Consent API is the right choice when the message cannot carry your hash, which is the case on the DLT-free route, and the right fallback when the Retriever times out. It works without permissions too, but the user sees a one-tap system prompt: “Allow MeeraPay to read this message?” with the SMS preview. One tap and your app receives the body.
// Start listening before the send call, optionally filtering by sender
SmsRetriever.getClient(context).startSmsUserConsent(null)
// In a receiver registered for SmsRetriever.SMS_RETRIEVED_ACTION:
CommonStatusCodes.SUCCESS -> {
val consentIntent = extras.getParcelable<Intent>(SmsRetriever.EXTRA_CONSENT_INTENT)
consentIntent?.let { consentLauncher.launch(it) } // ActivityResultLauncher<Intent>
}
// In the ActivityResult callback:
if (result.resultCode == Activity.RESULT_OK) {
val body = result.data?.getStringExtra(SmsRetriever.EXTRA_SMS_MESSAGE)
body?.let { Regex("""\b(\d{4,8})\b""").find(it)?.groupValues?.get(1) }?.let(onCode)
}
The sender filter argument accepts a phone number prefix. Indian transactional SMS arrives from a six-character header like AX-MERAPY rather than a number, so pass null and rely on the system’s OTP detection, which only offers messages that look like one-time codes anyway.
The trade-off is one extra tap. Meera’s team measured it: autofill completion with the Retriever was 96 percent of OTP screens; with User Consent it was 91 percent, and manual entry on devices without Play services was the rest. Both beat the 74 percent they had seen on the grandfathered READ_SMS path once Android 17 betas entered the fleet, because a withheld SMS is worse than a prompt.
Decide per route. If you send on the DLT-free route, ship User Consent only and keep the code simple. If you send through your own DLT template with the hash, ship the Retriever first and User Consent as the timeout fallback. Never ship both listeners at once for the same send; Play services delivers the message to whichever you started last, and the other one times out.
iOS 26, Emulator Testing and a Rollout Checklist
iOS went the opposite direction in the same year. iOS 26 extends one-time-code AutoFill to third-party chat, mail and browser apps, so a code that arrives in Messages is offered above the keyboard in more places. Nothing changes for native apps: keep textContentType = .oneTimeCode on the field and keep the message in the “483921 is your code” shape that iOS recognises. The same template serves both platforms, which is why the hash sits at the end rather than the start.
Test the Android change before Play auto-updates your users. Create an emulator with the Android 17 system image, install a debug build whose hash you computed from the debug keystore, and inject messages from the terminal:
# Send a fake OTP SMS into the running emulator (emulator console on port 5554)
adb -s emulator-5554 emu sms send AXMERAPY "483921 is your MeeraPay login code. Valid 5 minutes. <debug-hash>"
With the old READ_SMS build the field stays empty for three hours, which you can confirm by querying content://sms from the app and watching the row appear after the window. With the Retriever build the field fills within a second. Run the same test on an Android 16 image to be sure the new code path did not regress older devices, which are still the majority of the Indian fleet.
| Rollout step | Owner | Done when |
|---|---|---|
| Compute hash for debug, upload and Play App Signing keys | Android | Three values in server config, per variant |
| Decide route: own DLT template with hash, or DLT-free with User Consent | Backend | Template approved, or consent flow built |
Replace READ_SMS and RECEIVE_SMS with Retriever or Consent | Android | Permissions removed from manifest |
| Start listener before the send call, stop on screen exit | Android | No lost-race reports in staging |
| Keep message under 140 bytes after substitution | Backend | Length check in the send path |
| Test on Android 17, 16 and 13 emulators | QA | Autofill works on all three |
| Monitor OTP screen completion rate per Android version | Analytics | Dashboard split by API level |
The last row is the one teams skip. Android 17 reaches a fraction of devices at a time through OEM updates, so the regression appears as a slow decline in completion rate rather than a cliff. Split the metric by API level and you will see the fix land as the 17 cohort climbs back to parity. Our OTP SMS deliverability checklist has the rest of the delivery-side monitoring.
Frequently Asked Questions
Q: Does Android 17 block OTP SMS completely?
A: No. The message is delivered to the phone and shown in the default SMS app immediately. What Android 17 does is withhold it from other apps for three hours: the SMS_RECEIVED broadcast is not sent to them and content-provider queries filter it out. Apps using the SMS Retriever API or the SMS User Consent API receive the message normally because those paths are explicitly exempt.
Q: Can I use the SMS Retriever API with StartMessaging’s DLT-free OTP route?
A: Not with the Retriever, because the DLT-free route uses StartMessaging’s pre-approved template text and the 11-character app hash cannot be appended to it. Use the SMS User Consent API on that route; it needs nothing special in the message and costs the user one tap. If you register your own DLT template with a trailing variable and send with templateId plus the hash in variables, the Retriever works.
Q: Will my existing READ_SMS permission keep working on older Android versions?
A: On Android 16 and earlier the permission still functions, but Google Play policy has restricted it to default SMS and backup apps since 2019, so a store review can reject the app regardless of Android version. Migrating to the Retriever or User Consent API removes the permission from the manifest and fixes both the policy risk and the Android 17 behaviour at once.
Q: Does the app hash change when I publish through Play App Signing?
A: Yes. The hash is derived from the package name and the certificate that signs the installed APK. Play App Signing re-signs your upload with Google’s key, so the hash on users’ devices is computed from that certificate, not your upload key. Compute and configure one hash per signing identity: debug, upload (for internal testing tracks) and the Play App Signing certificate for production.
Meera’s OTP screen on the Android 17 Pixel now fills in 1.2 seconds, the READ_SMS permission is gone from the manifest, and the Play review that had flagged it for two years closed itself. Her backend still sends the same six-digit code through the same POST /otp/send call; the only new byte on the wire is an eleven-character hash at the end of a DLT template. If your app reads OTPs from the inbox today, the Android 17 cohort is already in your fleet. Start sending through the StartMessaging OTP API at ₹0.25 per OTP with no DLT registration required, wire up the User Consent API this sprint, and create your account to test the flow before the next OEM update lands.
StartMessaging Team
StartMessaging Team