Skip to content

Getting Started

Terminal window
bun add @capgo/capacitor-android-sms-retriever
bunx cap sync android
import { AndroidSmsRetriever } from '@capgo/capacitor-android-sms-retriever';

SMS Retriever requires Google Play services on the Android device. The plugin does not request READ_SMS or RECEIVE_SMS permissions.

Your verification SMS must include the app hash returned by getHashString(). Generate the hash for the signing key used to distribute the app. Debug, release, and Play App Signing builds can have different hashes.

import { AndroidSmsRetriever } from '@capgo/capacitor-android-sms-retriever';
const received = await AndroidSmsRetriever.addListener('smsReceived', ({ message }) => {
const code = message.match(/\b\d{6}\b/)?.[0];
console.log('Verification code:', code);
});
const timeout = await AndroidSmsRetriever.addListener('smsRetrieverTimeout', () => {
console.log('SMS Retriever timed out');
});
const errors = await AndroidSmsRetriever.addListener('smsRetrieverError', ({ message }) => {
console.error('SMS Retriever error:', message);
});
await AndroidSmsRetriever.startWatch();
// Remove listeners when the verification flow is done.
await received.remove();
await timeout.remove();
await errors.remove();
await AndroidSmsRetriever.stopWatch();
const { hash } = await AndroidSmsRetriever.getHashString();
console.log(hash);

Use this hash at the end of the verification SMS sent by your backend.

const { phoneNumber } = await AndroidSmsRetriever.getPhoneNumber();
console.log(phoneNumber);

Android shows the native Phone Number Hint UI and returns the phone number selected by the user.

<#> 123456 is your verification code.
FA+9qCX9VSu

Replace the final line with the hash for your app signing key.