@capawesome/capacitor-android-sms-retriever 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -3
- package/package.json +13 -3
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Capacitor Android SMS Retriever Plugin
|
|
2
2
|
|
|
3
3
|
Capacitor plugin for OTP autofill on Android via the SMS User Consent and Phone Number Hint APIs.
|
|
4
4
|
|
|
@@ -17,9 +17,13 @@ Capacitor plugin for OTP autofill on Android via the SMS User Consent and Phone
|
|
|
17
17
|
|
|
18
18
|
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## Use Cases
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
The Android SMS Retriever plugin is typically used in phone number verification flows, for example:
|
|
23
|
+
|
|
24
|
+
- **OTP autofill**: Retrieve an incoming verification SMS after a one-tap system consent dialog and extract the one-time code, so the user doesn't have to type it manually.
|
|
25
|
+
- **Phone number prefill**: Prefill the phone number input field of your sign-up or login form via the system bottom sheet.
|
|
26
|
+
- **Play-policy-safe SMS verification**: Implement SMS-based verification without requesting any SMS permissions, using the SMS User Consent and Phone Number Hint APIs.
|
|
23
27
|
|
|
24
28
|
## Compatibility
|
|
25
29
|
|
|
@@ -76,6 +80,12 @@ No configuration required for this plugin.
|
|
|
76
80
|
|
|
77
81
|
## Usage
|
|
78
82
|
|
|
83
|
+
The following examples show how to prefill the user's phone number and retrieve a verification SMS.
|
|
84
|
+
|
|
85
|
+
### Prefill the user's phone number
|
|
86
|
+
|
|
87
|
+
Request the user's phone number via the Phone Number Hint API. A system bottom sheet is displayed that lets the user pick one of the phone numbers associated with the device, for example to prefill a phone number input field. Only available on Android:
|
|
88
|
+
|
|
79
89
|
```typescript
|
|
80
90
|
import { AndroidSmsRetriever } from '@capawesome/capacitor-android-sms-retriever';
|
|
81
91
|
|
|
@@ -83,6 +93,14 @@ const requestPhoneNumber = async () => {
|
|
|
83
93
|
const { phoneNumber } = await AndroidSmsRetriever.requestPhoneNumber();
|
|
84
94
|
return phoneNumber;
|
|
85
95
|
};
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Retrieve a verification SMS
|
|
99
|
+
|
|
100
|
+
Retrieve an incoming verification SMS via the SMS User Consent API. A system consent dialog is displayed when a matching SMS is received, and the promise resolves with the full message text once the user consents, so your app can extract the one-time code itself (see [Extracting the One-Time Code](#extracting-the-one-time-code)). Only available on Android:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import { AndroidSmsRetriever } from '@capawesome/capacitor-android-sms-retriever';
|
|
86
104
|
|
|
87
105
|
const retrieveSms = async () => {
|
|
88
106
|
const { message } = await AndroidSmsRetriever.retrieveSms();
|
|
@@ -197,6 +215,46 @@ For the SMS User Consent API to detect a message, the SMS must:
|
|
|
197
215
|
|
|
198
216
|
The underlying broadcast waits up to 5 minutes for a matching SMS. If no message is received within this time, the promise rejects with the error code `TIMEOUT`.
|
|
199
217
|
|
|
218
|
+
## FAQ
|
|
219
|
+
|
|
220
|
+
### How is this plugin different from other similar plugins?
|
|
221
|
+
|
|
222
|
+
It implements OTP autofill on Android through the SMS User Consent and Phone Number Hint APIs, so you can read a verification SMS and prefill the user's phone number without requesting any SMS permissions and while staying within Google Play policy. It's a focused, fully typed API that handles the system consent dialog and bottom sheet for you, and it's actively maintained against the latest Capacitor and Android versions. On iOS you don't need it at all — the WebView already autofills one-time codes — and the README explains exactly how.
|
|
223
|
+
|
|
224
|
+
### Does this plugin require any SMS permissions?
|
|
225
|
+
|
|
226
|
+
No, the plugin uses the SMS User Consent and Phone Number Hint APIs, which are Play-policy-safe and require no SMS permissions. Instead of reading SMS messages silently, the user explicitly consents via a one-tap system dialog before your app receives the message.
|
|
227
|
+
|
|
228
|
+
### Does this plugin work on iOS or Web?
|
|
229
|
+
|
|
230
|
+
No, this plugin only provides an Android implementation and you don't need one on iOS. iOS already autofills one-time codes from incoming SMS messages in `WKWebView` when the input field uses `autocomplete="one-time-code"`. On iOS and Web, all methods reject as unimplemented.
|
|
231
|
+
|
|
232
|
+
### Why does `retrieveSms` reject with the error code `TIMEOUT`?
|
|
233
|
+
|
|
234
|
+
The underlying broadcast waits up to 5 minutes for a matching SMS. If no matching message is received within this time, the promise rejects with the error code `TIMEOUT`. Make sure the SMS is sent while the broadcast is active and meets the requirements of the SMS User Consent API.
|
|
235
|
+
|
|
236
|
+
### Why is my SMS message not detected?
|
|
237
|
+
|
|
238
|
+
For the SMS User Consent API to detect a message, the SMS must contain a one-time code that the user sends back to your server to complete the verification, be no longer than 140 bytes, and not originate from a phone number in the user's contacts. See [Extracting the One-Time Code](#extracting-the-one-time-code) for more information.
|
|
239
|
+
|
|
240
|
+
### Can I filter incoming messages by sender?
|
|
241
|
+
|
|
242
|
+
Yes, you can pass the `senderPhoneNumber` option to the `retrieveSms(...)` method to only retrieve messages from a specific sender. If not provided, the SMS from any sender is retrieved.
|
|
243
|
+
|
|
244
|
+
### Can I use this plugin with Ionic, React, Vue or Angular?
|
|
245
|
+
|
|
246
|
+
Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.
|
|
247
|
+
|
|
248
|
+
## Related Plugins
|
|
249
|
+
|
|
250
|
+
- [SMS Composer](https://capawesome.io/docs/sdks/capacitor/sms-composer/): Open the native SMS composer prefilled with recipients and a message body.
|
|
251
|
+
- [Password Autofill](https://capawesome.io/docs/sdks/capacitor/password-autofill/): Save passwords to the platform credential store.
|
|
252
|
+
- [SIM](https://capawesome.io/docs/sdks/capacitor/sim/): Read SIM card and carrier information.
|
|
253
|
+
|
|
254
|
+
## Newsletter
|
|
255
|
+
|
|
256
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
257
|
+
|
|
200
258
|
## Changelog
|
|
201
259
|
|
|
202
260
|
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/android-sms-retriever/CHANGELOG.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capawesome/capacitor-android-sms-retriever",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Capacitor plugin for OTP autofill on Android via the SMS User Consent and Phone Number Hint APIs.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -33,11 +33,21 @@
|
|
|
33
33
|
"url": "https://opencollective.com/capawesome"
|
|
34
34
|
}
|
|
35
35
|
],
|
|
36
|
-
"homepage": "https://capawesome.io/docs/
|
|
36
|
+
"homepage": "https://capawesome.io/docs/sdks/capacitor/android-sms-retriever/",
|
|
37
37
|
"keywords": [
|
|
38
38
|
"capacitor",
|
|
39
|
+
"capacitor-plugin",
|
|
39
40
|
"plugin",
|
|
40
|
-
"native"
|
|
41
|
+
"native",
|
|
42
|
+
"android",
|
|
43
|
+
"sms retriever",
|
|
44
|
+
"otp",
|
|
45
|
+
"otp autofill",
|
|
46
|
+
"one-time code",
|
|
47
|
+
"sms verification",
|
|
48
|
+
"sms user consent",
|
|
49
|
+
"phone number hint",
|
|
50
|
+
"phone verification"
|
|
41
51
|
],
|
|
42
52
|
"scripts": {
|
|
43
53
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|