开始使用
复制一个包含安装步骤和此插件的完整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.
bun add @capgo/capacitor-android-sms-retrieverbunx cap sync androidimport { AndroidSmsRetriever } from '@capgo/capacitor-android-sms-retriever';安卓要求
Android 要求SMS Retriever 需要在 Android 设备上安装 Google Play 服务。该插件不会请求任何权限。 READ_SMS 或 RECEIVE_SMS 您的验证短信必须包含由
生成用于分发应用的签名密钥的哈希值。调试、发布和 Play App Signing 构建可以具有不同的哈希值。 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();SMS Retriever 需要在 Android 设备上安装 Google Play 服务。该插件不会请求任何权限。
您的验证短信必须包含由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将应用程序签名密钥的哈希替换为短信的最后一行。