Getting Started
复制一个包含安装步骤和本插件的完整Markdown指南的设置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-android-sms-retriever`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/android-sms-retriever/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Install
Section titled “Install”bun add @capgo/capacitor-android-sms-retrieverbunx cap sync androidImport
Section titled “Import”import { AndroidSmsRetriever } from '@capgo/capacitor-android-sms-retriever';Android Requirements
Android 设备要求SMS Retriever 需要在 Android 设备上安装 Google Play 服务。该插件不会请求任何权限。 READ_SMS Your 验证 SMS 必须包含由 RECEIVE_SMS 用于分发应用的签名密钥生成的应用哈希。 Debug、release 和 Play App Signing 构建可以具有不同的哈希。
监听验证 SMS getHashString()复制到剪贴板
停止观看
复制到剪贴板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();Section titled “Listen For A Verification SMS”
Section titled “Stop Watching”await AndroidSmsRetriever.stopWatch();获取应用程序哈希
标题:获取应用程序哈希const { hash } = await AndroidSmsRetriever.getHashString();console.log(hash);在您的后端发送的验证短信末尾使用此哈希。
请求电话号码提示
标题:请求电话号码提示const { phoneNumber } = await AndroidSmsRetriever.getPhoneNumber();console.log(phoneNumber);Android显示原生电话号码提示UI,并返回用户选择的电话号码。
示例短信
标题:示例短信<#> 123456 is your verification code.FA+9qCX9VSu将应用签名密钥的哈希替换为短信末尾的行。
继续从 Getting Started
标题:继续从 Getting Started如果您正在使用 Getting Started 来规划原生插件工作,连接它与 使用 @capgo/capacitor-android-sms-retriever 原生功能在使用 @capgo/capacitor-android-sms-retriever 中 Capgo 插件目录 Capgo 插件目录中的产品工作流 Capacitor 由 Capgo 的插件 Capacitor 由 Capgo 的插件实现细节 添加或更新插件 关于在添加或更新插件时的实现细节 Ionic企业版插件替代品 关于Ionic企业版插件替代品的产品工作流程