# cordova-plugin-android-sms-retriever

> A plugin to use the SMS Retriever Android API to receive text messages without requiring SMS permissions

Latest version **1.0.4** (published 2019-01-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install cordova-plugin-android-sms-retriever
pnpm add cordova-plugin-android-sms-retriever
yarn add cordova-plugin-android-sms-retriever
bun add cordova-plugin-android-sms-retriever
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2019-01-14 |
| First published | 2019-01-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Diego Morais |
| Maintainers | diegosiao |
| Keywords | ecosystem:cordova, cordova-android |

## Links

- npm: https://www.npmjs.com/package/cordova-plugin-android-sms-retriever
- Repository: https://github.com/diegosiao/cordova-plugin-android-sms-retriever
- Homepage: https://github.com/diegosiao/cordova-plugin-android-sms-retriever#readme
- Issues: https://github.com/diegosiao/cordova-plugin-android-sms-retriever/issues
- npm.io page: https://npm.io/package/cordova-plugin-android-sms-retriever

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2019-01-14
- 1.0.3 — 2019-01-11
- 1.0.2 — 2019-01-11
- 1.0.1 — 2019-01-11

## README

# cordova-plugin-android-sms-retriever

This plugin uses the Android [**SMS Retriever API**](https://developers.google.com/identity/sms-retriever/overview) to intercept text messages sent to the phone.

## Why is that?

On **January/2019** Google started warning developers about critical changes in SMS and CALL LOGS access policy. Android used to allow apps to read or intercept SMS indiscriminately since they had the permissions: SMS_READ and/or CALL_LOG. That is an **obvious security issue** since several financial operations rely on tokens or OTP (One Time Passwords) sent through SMS to their users. [More info...](https://www.zdnet.com/article/google-restricts-which-android-apps-can-request-call-log-and-sms-permissions/)

Regarding to SMS, Google presents as an alternative the [**SMS Retriever API**](https://developers.google.com/identity/sms-retriever/overview) used by this plugin.

## Installation

    cordova plugin add cordova-plugin-android-sms-retriever
---

# API Reference <a name="reference"></a>

* [cordova.plugins.AndroidSmsRetriever](#module_androidSmsRetriever)
    * [.getAppHash(successCallback, errorCallback)](#module_androidSmsRetriever.getAppHash)
    * [.onSmsReceived(successCallback, errorCallback, notifyWhenStarted)](#module_androidSmsRetriever.onSmsReceived)

<a name="module_androidSmsRetriever"></a>

## AndroidSmsRetriever
<a name="module_androidSmsRetriever.getAppHash"></a>

### .getAppHash(successCallback, errorCallback)
Since computing the 11 characters portion of your app's hash required by SMS retriever API to be in the text message body can be a tedious workload, this plugin provides this function as an utility. 

**IMPORTANT:** Since you get your app's hash, you should remove the call to this function. Also, remember this hash uses the certicate used to sign the APK so consider this information if you face issues to intercept SMS.

    // Remove this code after getting your app's hash
    // The hash might be different when building a release version
    if (device.platform === 'Android') {

        cordova.plugins.AndroidSmsRetriever
            .getAppHash(
                
                function successCallback(hash) {
                    alert(hash);
                },

                function errorCallback(e) {
                    console.error(e);
                }

            );
    }

If you are facing difficulties to generate your app's hash using this function refer to documentation provided by Google [here](https://developers.google.com/identity/sms-retriever/verify#computing_your_apps_hash_string). 

<a name="module_androidSmsRetriever.onSmsReceived"></a>
### .onSmsReceived(successCallback, errorCallback, notifyWhenStarted)

**successCallback** The function to be called when a SMS arrives. 

**errorCallback** The error callback will be called if something goes wrong or if no SMS arrives within **5 minutes**.

**notifyWhenStarted** An optional boolean that determines if the successCallback should also be called when the SMS retriever starts. The value returned in the message parameter of the successCallback will be the constant 'SMS_RETRIEVER_SETUP'.

Useful when you want to make sure the native SMSretriever listener is up and running before requesting your server to send the text message.


    if (device.platform === 'Android') {

        cordova.plugins.AndroidSmsRetriever
            .onSmsReceived(
                
                function successCallback(message) {

                    if(message === 'SMS_RETRIEVER_SETUP') {
                        // Here you request server to send the SMS
                        return;
                    }

                    alert(message);
                },

                function errorCallback(e) {
                    console.error(e);
                },

                true //notifyWhenStarted
            );
    }
    
**IMPORTANT:** The body of your SMS needs to comply the Android SMS Retriever API requirements described [here](https://developers.google.com/identity/sms-retriever/verify#1_construct_a_verification_message). Basically you need to start with the "<#>" tag and finish with the 11 character code extracted from your app's hash, in the example below **FA+9qCX9VSu**.

##### SMS example

    <#> Your ExampleApp code is: 123ABC78
    FA+9qCX9VSu

---
_Source: https://npm.io/package/cordova-plugin-android-sms-retriever · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
