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.
What each autofill level needs
Section titled “What each autofill level needs”| 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 can’t run it
Section titled “Expo Go can’t run it”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 exposesgetHash()andstartOtpListener(). - A local Expo module (
npx create-expo-module --local). It’s about 50 lines of Kotlin: callSmsRetriever.getClient(context).startSmsRetriever(), register a receiver forSMS_RETRIEVED_ACTION, and send the message to JS as an event. Addcom.google.android.gms:play-services-auth-api-phoneas a Gradle dependency.
How the flow works
Section titled “How the flow works”- The app starts the retriever before it asks the backend to send the code. The retriever listens for 5 minutes.
- The backend sends an SMS of at most 140 bytes that contains the code and ends with the 11-character app hash.
- Android matches the hash to your app and passes the full message text to it. No SMS permission is involved.
- The app extracts the digits and fills the input.
Your code: 482913FA+9qCX9VSuThe app hash
Section titled “The app hash”The hash is the first 11 characters of a base64-encoded SHA-256 digest of two inputs:
- the package name (
android.packageinapp.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.
One hash per signing key
Section titled “One hash per signing key”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.
Getting the hash
Section titled “Getting the hash”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:
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-11Where 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.
When you can’t change the SMS
Section titled “When you can’t change the SMS”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.