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.
您可以使用我们的 AI 助手设置来安装插件。使用以下命令将 Capgo 技能添加到您的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-android-sms-retriever` plugin in my project.如果您更喜欢手动设置,请按照以下命令安装插件并遵循以下平台特定的说明:
bun add @capgo/capacitor-android-sms-retrieverbunx cap sync androidimport { AndroidSmsRetriever } from '@capgo/capacitor-android-sms-retriever';Android 需求
Section titled “Android 需求”SMS 检索器需要在 Android 设备上安装 Google Play 服务。该插件不请求任何权限。 READ_SMS 您的验证短信必须包含由 RECEIVE_SMS 生成用于分发应用的签名密钥的哈希值。调试、发布和 Play App Signing 构建可以具有不同的哈希值。
监听验证短信 getHashString()Section titled “监听验证短信”
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);在您的后端发送的验证短信末尾使用此哈希。
请求电话号码提示
标题:请求电话号码提示const { phoneNumber } = await AndroidSmsRetriever.getPhoneNumber();console.log(phoneNumber);在 Android 上,native 电话号码提示 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 企业插件替代品的产品工作流程