npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-android-sms-retriever-api

v1.0.5

Published

Cordova plugin to enable single SMS reception in Android using the SMS Retriever API

Downloads

96

Readme

Cordova Plugin Android SMS Retriever API

Cordova plugin to enable single SMS reception in Android using the SMS Retriever API in order to read automatically one-time passwords from SMS messages.

This plugin is intended to comply with the critical changes introduced by Google in 2019 in SMS and CALL LOGS policies and does not need extra permissions to work.

Installation

The installation requires cordova 6.0+.

Use the cordova client in order to install the package.

$ cordova plugin add cordova-plugin-android-sms-retriever-api

Configuration

The plugin requires the Google libraries com.google.android.gms:play-services-auth and com.google.android.gms:play-services-auth-api-phone.

The default versions of this two libraries has been set to 15.+, but you can configure the version you want by defining the PLAY_SERVICES_AUTH_VERSION and PLAY_SERVICES_AUTH_API_PHONE_VERSION preferences in config.xml or package.json.

Example

<platform name="android">
  <preference name="PLAY_SERVICES_AUTH_VERSION" value="17.+" />
</platform>

SMS message preparation

To use the SMS Retriever API you need to include a text signature in your SMS content. You can find more about this topic in the Google Developers Guide

Basic Usage

To start listening for a single incoming SMS with a verification code during 5 minutes use the following method.

cordova.plugins.smsRetriever.start(function() {
	// Listener registered successfully
}, function(err) {
	// Failed to register listener
	console.error(err);
});

Calling the above method will only start listening for incoming SMS messages with the application signature. In order to attach an event handler to the SMS received event you will have to call the "on" method.

cordova.plugins.smsRetriever.on('smsReceived', function(smsMessage) {
  // Sms received
  console.error(smsMessage);
});

API reference

cordova.plugins.smsRetriever.start(successHandler, errorHandler)

Starts listening for one single SMS message during 5 minutes.

Parameters

| Parameter | Type | Default | Description | | ---------------- | ---------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | successHandler | Function | | Is called when the plugin successfully starts listening number. | | errorHandler | Function | | Is called when the plugin encounters an error while trying to start listening number. |

Example

cordova.plugins.smsRetriever.start(function() {
	// Listener registered successfully
}, function(err) {
	// Failed to register listener
	console.error(err);
});

cordova.plugins.smsRetriever.stop(successHandler, errorHandler)

Stops listening for SMS messages

Parameters

| Parameter | Type | Default | Description | | ---------------- | ---------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | successHandler | Function | | Is called when the plugin successfully stops listening number. | | errorHandler | Function | | Is called when the plugin encounters an error while trying to stop listening number. |

Example

cordova.plugins.smsRetriever.stop(function() {
	// Listener registered successfully
}, function(err) {
	// Failed to register listener
	console.error(err);
});

cordova.plugins.smsRetriever.on(eventName, eventHandler)

Registers an event handler for the event name.

Parameters

| Parameter | Type | Default | Description | | ---------- | ---------- | ------- | ------------------------------------------------------------------ | | eventName | string | | Name of the event to listen to. See below for all the event names. | | eventHandler | Function | | Is called when the event is triggered.

cordova.plugins.smsRetriever.on('smsReceived', eventHandler)

Fired when the listener receives an SMS message.

Callback parameters

| Parameter | Type | Description | | ----------------------- | -------- | ------------------------------------------------------------------------------- | | smsMessage | string | The complete received SMS message |

Example

cordova.plugins.smsRetriever.on('smsReceived', (smsMessage) => {
  // Sms received
  console.error('This is the content of the SMS message: ' + smsMessage);
});

cordova.plugins.smsRetriever.on('timeout', eventHandler)

Fired when the listener stops listening after 5 minutes from start.

cordova.plugins.smsRetriever.off(eventName, eventHandler)

Unregisters an event handler for the event name. If eventHandler is not defined, unregisters all events of the eventName.

Parameters

| Parameter | Type | Default | Description | | ---------- | ---------- | ------- | ------------------------------------------------------------------ | | eventName | string | | Name of the event to unregister. | | eventHandler | Function | | The eventHandler to unregister. If not provided, all the events of the eventName will be unregistered |

Example

cordova.plugins.smsRetriever.off('smsReceived');

Further Considerations

Debugging SMS reception

If you want to debug the SMS reception with Android Studio, remember to include the same signing configuration as the one you have used to create the SMS text signature in the app Module by right clicking in your project, chosing the Open Module Settings option and selecting the app Module.

App signing by Google Play

If you use the App signing by Google Play feature, the applications downloaded from Google Play Store will have a different signature than the one used by you to sign the apk.

In this case, you will have to download the App signing certificate of the app from the Google Play Console, use the certificate to create a .jks and use this file to obtain the 11 characters signature that should be attached to the SMS.

License

Copyright © 2020 José Lorente Martín [email protected].

Licensed under the BSD 3-Clause License. See LICENSE.txt for details.