@capgo/capacitor-android-sms-retriever

中文文档
8.1.2发布于 2026/10/15MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 4.3万

Capacitor plugin for Android SMS Retriever and Phone Number Hint APIs.

原始使用文档
文档目录17 节
  1. ➡️ Get started for free
  2. Key features
  3. Install
  4. Android
  5. Usage
  6. API
  7. startWatch()
  8. stopWatch()
  9. getHashString()
  10. getPhoneNumber()
  11. addListener('smsReceived', ...)
  12. addListener('smsRetrieverTimeout', ...)
  13. addListener('smsRetrieverError', ...)
  14. removeAllListeners()
  15. getPluginVersion()
  16. Interfaces
  17. Type Aliases

@capgo/capacitor-android-sms-retriever

Read one-time codes from SMS on Android without the SMS permission, using Google Play services SMS Retriever, and let users pick their phone number with Phone Number Hint. Smoother sign-in and verification flows.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-android-sms-retriever in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-android-sms-retriever to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-android-sms-retriever for Capacitor apps

Key features

  • SMS Retriever: startWatch() waits for one verification SMS and emits smsReceived, with smsRetrieverTimeout and smsRetrieverError events.
  • No SMS permission: Google Play services delivers the matching message, so you do not request READ_SMS.
  • App hash: getHashString() returns the 11-character hash your server adds to the SMS.
  • Phone Number Hint: getPhoneNumber() shows the system picker and returns the selected SIM number.
  • Stop anytime: stopWatch() cancels the active watch.
  • Platforms: Android. Android only. iOS and web are not supported.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-android-sms-retriever` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

bun add @capgo/capacitor-android-sms-retriever
bunx cap sync android

Android

This plugin does not request SMS permissions. SMS retrieval uses Google Play services and waits for one matching verification SMS for up to five minutes.

The verification SMS must include the app hash returned by getHashString().

Usage

import { AndroidSmsRetriever } from '@capgo/capacitor-android-sms-retriever';

const { hash } = await AndroidSmsRetriever.getHashString();
console.log('SMS hash:', hash);

const received = await AndroidSmsRetriever.addListener('smsReceived', ({ message }) => {
  console.log('Verification SMS:', message);
});

await AndroidSmsRetriever.addListener('smsRetrieverTimeout', () => {
  console.log('SMS Retriever timed out');
});

await AndroidSmsRetriever.startWatch();

// Later, if needed:
await AndroidSmsRetriever.stopWatch();
await received.remove();
const { phoneNumber } = await AndroidSmsRetriever.getPhoneNumber();
console.log(phoneNumber);

API

Android-only Capacitor plugin for Google Play services SMS Retriever and Phone Number Hint APIs.

startWatch()

startWatch() => Promise<StartWatchResult>

Start listening for one verification SMS through Android's SMS Retriever API.

Android stops listening automatically when a matching message arrives or after the five-minute SMS Retriever timeout. No SMS permissions are required.

Returns: Promise<StartWatchResult>

Since: 8.0.0


stopWatch()

stopWatch() => Promise<StopWatchResult>

Stop the active SMS Retriever watch, if any.

Returns: Promise<StopWatchResult>

Since: 8.0.0


getHashString()

getHashString() => Promise<GetHashStringResult>

Get the 11-character app hash for the installed app signature.

Generate this once for the signing key used to distribute the app and append it to verification SMS messages.

Returns: Promise<GetHashStringResult>

Since: 8.0.0


getPhoneNumber()

getPhoneNumber() => Promise<GetPhoneNumberResult>

Show Android's Phone Number Hint UI and return the user-selected SIM-based phone number.

Returns: Promise<GetPhoneNumberResult>

Since: 8.0.0


addListener('smsReceived', ...)

addListener(eventName: 'smsReceived', listenerFunc: (event: SmsReceivedEvent) => void) => Promise<PluginListenerHandle>

Listen for a verification SMS received after {@link startWatch}.

ParamType
eventName'smsReceived'
listenerFunc(event: SmsReceivedEvent) => void

Returns: Promise<PluginListenerHandle>

Since: 8.0.0


addListener('smsRetrieverTimeout', ...)

addListener(eventName: 'smsRetrieverTimeout', listenerFunc: () => void) => Promise<PluginListenerHandle>

Listen for the five-minute SMS Retriever timeout.

ParamType
eventName'smsRetrieverTimeout'
listenerFunc() => void

Returns: Promise<PluginListenerHandle>

Since: 8.0.0


addListener('smsRetrieverError', ...)

addListener(eventName: 'smsRetrieverError', listenerFunc: (event: SmsRetrieverErrorEvent) => void) => Promise<PluginListenerHandle>

Listen for SMS Retriever runtime errors after {@link startWatch}.

ParamType
eventName'smsRetrieverError'
listenerFunc(event: SmsRetrieverErrorEvent) => void

Returns: Promise<PluginListenerHandle>

Since: 8.0.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all registered listeners for this plugin.

Since: 8.0.0


getPluginVersion()

getPluginVersion() => Promise<PluginVersionResult>

Get the native Capacitor plugin version.

Returns: Promise<PluginVersionResult>

Since: 8.0.0


Interfaces

StartWatchResult

Result returned when SMS Retriever watching starts.

PropTypeDescriptionSince
statusSmsRetrieverStartStatusNative status returned by Android.8.0.0

StopWatchResult

Result returned when SMS Retriever watching stops.

PropTypeDescriptionSince
status'SMS_RETRIEVER_DONE'Native status returned by Android.8.0.0

GetHashStringResult

Result returned by {@link AndroidSmsRetrieverPlugin.getHashString}.

PropTypeDescriptionSince
hashstringThe 11-character app hash that must be appended to verification SMS messages.8.0.0

GetPhoneNumberResult

Result returned by {@link AndroidSmsRetrieverPlugin.getPhoneNumber}.

PropTypeDescriptionSince
phoneNumberstringPhone number selected by the user from Android's Phone Number Hint UI.8.0.0

PluginListenerHandle

PropType
remove() => Promise<void>

SmsReceivedEvent

SMS Retriever message event payload.

PropTypeDescriptionSince
messagestringFull verification SMS message received by Android's SMS Retriever API.8.0.0

SmsRetrieverErrorEvent

SMS Retriever error event payload.

PropTypeDescriptionSince
messagestringError message returned by Android or Google Play services.8.0.0

PluginVersionResult

Plugin version payload.

PropTypeDescriptionSince
versionstringVersion identifier returned by the platform implementation.8.0.0

Type Aliases

SmsRetrieverStartStatus

Status values returned by {@link AndroidSmsRetrieverPlugin.startWatch}.

'SMS_RETRIEVER_STARTED' | 'SMS_RETRIEVER_ALREADY_STARTED'

版本与发布记录

@capgo/capacitor-android-sms-retriever 共发布 16 个版本,首次发布于 2026/05/06;过去 12 个月发布了 16 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.1.2latest2026/10/1525 天前
8.1.12026/10/1327 天前
8.1.02026/10/091 个月前
8.0.132026/10/081 个月前
8.0.122026/09/161 个月前
8.0.112026/09/151 个月前

关于 @capgo/capacitor-android-sms-retriever 的常见问题

@capgo/capacitor-android-sms-retriever 是什么?

Capacitor plugin for Android SMS Retriever and Phone Number Hint APIs.

如何安装 @capgo/capacitor-android-sms-retriever?

在项目目录运行 npm install @capgo/capacitor-android-sms-retriever,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-android-sms-retriever 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-android-sms-retriever 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-android-sms-retriever 可以商用吗?

@capgo/capacitor-android-sms-retriever 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-android-sms-retriever 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-android-sms-retriever 在 2026/10/09 – 2026/11/07 这 30 天内被下载 42,982 次,日均约 1,433 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-android-sms-retriever 还在维护吗?

最新版本 8.1.2 发布于 2026/10/15(25 天前);至今共发布 16 个版本,其中过去 12 个月发布了 16 个;首次发布于 2026/05/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。