Skip to content

Android SMS Retriever in Expo: How the App Hash Works

When you add SMS code login to an Expo app, setting autoComplete="one-time-code" and textContentType="oneTimeCode" on the input gets you one-tap autofill. iOS shows the code above the keyboard, and Gboard suggests it on Android. To go further on Android and fill the code with no tap at all, you need the SMS Retriever API. That API runs in native code and depends on an app hash that is easy to misunderstand.

Level Platform What it needs
One tap iOS, Android, Safari textContentType="oneTimeCode" and autoComplete="one-time-code" on the TextInput
One tap, system prompt Android SMS User Consent API: native code, no change to the SMS
Zero tap Android SMS Retriever API: native code, and the SMS must end with the app hash

iOS offers nothing beyond the one-tap suggestion.

Expo Go only contains the native modules it ships with, and SMS Retriever isn’t one of them. You need a development build (npx expo run:android or EAS Build). The rest of the stack doesn’t change: you still write TypeScript, use Expo Router and install packages with npx expo install.

You don’t need much Kotlin either. You have two options:

  • A library such as react-native-otp-verify, which wraps the API and exposes getHash() and startOtpListener().
  • A local Expo module (npx create-expo-module --local). It’s about 50 lines of Kotlin: call SmsRetriever.getClient(context).startSmsRetriever(), register a receiver for SMS_RETRIEVED_ACTION, and send the message to JS as an event. Add com.google.android.gms:play-services-auth-api-phone as a Gradle dependency.
  1. The app starts the retriever before it asks the backend to send the code. The retriever listens for 5 minutes.
  2. The backend sends an SMS of at most 140 bytes that contains the code and ends with the 11-character app hash.
  3. Android matches the hash to your app and passes the full message text to it. No SMS permission is involved.
  4. The app extracts the digits and fills the input.
Your code: 482913
FA+9qCX9VSu

The hash is the first 11 characters of a base64-encoded SHA-256 digest of two inputs:

  • the package name (android.package in app.json)
  • the signing certificate of the installed APK

The build number, app version and JS bundle aren’t inputs. So the hash doesn’t change on every build. You create a signing key once and sign every build with it, so every build signed with that key has the same hash.

The hash changes when the key changes. A typical project has two or three keys, so it has two or three hashes:

Build Signed with Hash
Local dev build Debug keystore Hash A
EAS internal or preview build Keystore EAS generates once per project Hash B
Play Store install Google Play App Signing key Hash C

The Play Store row is where most people get caught. With Play App Signing, Google re-signs your upload with its own key, so the production hash is not the hash of the key you upload with. If you test with an EAS build and ship that hash, autofill silently stops working in production.

The hash only changes if you change the package name (a .dev variant gets its own hash) or replace the signing key, which is rare.

You can read it at runtime on the device:

import { getHash } from "react-native-otp-verify";
const [hash] = await getHash();
console.log(hash); // "FA+9qCX9VSu"

Or compute it from a keystore. For the production hash, first download the app signing certificate from Play Console under App integrity and import it into a keystore:

Terminal window
keytool -exportcert -alias <alias> -keystore <keystore> \
| xxd -p | tr -d "[:space:]" \
| echo -n com.example.app `cat` \
| sha256sum | tr -d "[:space:]-" \
| xxd -r -p | base64 | cut -c1-11

Where the hash lives: backend config or sent by the app

Section titled “Where the hash lives: backend config or sent by the app”

The frontend can’t add the hash to the SMS. The backend writes the message, so the backend has to append it. There are two ways to give the backend the hash.

Stored in backend config (recommended). Compute each hash once and store it per environment: the EAS or debug hash on staging, the Play hash on production. The backend appends it to every SMS, and the app sends nothing extra. Google’s own helper sample says to compute the hash once, store it on the server, and leave the helper out of the production app. The hash almost never changes, so a one-time setup is enough.

Sent by the app. The app calls getHash() and sends the result with the “send code” request, and the backend appends whatever it receives. Every build works without config. The backend must validate the value strictly (exactly 11 characters, base64 alphabet only). Otherwise a client can inject its own text into SMS messages sent in your name.

If the backend or SMS provider can’t append a hash, use the SMS User Consent API instead. It needs native code too, but no hash: when the SMS arrives, Android asks the user to allow the app to read that one message. That’s one tap instead of zero, with no change to the backend.

Want help with this in your own project? See my services: React Native mobile apps.