New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-native-sms-retriever

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-sms-retriever

Android SMS Retriever API for React Native

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.5K
decreased by-11.23%
Maintainers
1
Weekly downloads
 
Created
Source

Platform License

Cover

With the SMS Retriever API, you can perform SMS-based user verification in your Android app automatically, without requiring the user to manually type verification codes, and without requiring any extra app permissions.


Read Phone Number Read SMS


Installation

npm install --save react-native-sms-retriever
react-native link react-native-sms-retriever
  1. Add the following lines to android/settings.gradle:
include ':react-native-sms-retriever'
project(':react-native-sms-retriever').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sms-retriever/android')
  1. Add the compile line to the dependencies in android/app/build.gradle:
dependencies {
  // ...
  compile project(':react-native-sms-retriever')
}
  1. Add the import and link the package in MainApplication.java:
import me.furtado.smsretriever.RNSmsRetrieverPackage; // <-- Add the import

public class MainApplication extends Application implements ReactApplication {

  // ...

  @Override
  protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
      // ...
      new RNSmsRetrieverPackage() // <-- Add it to the packages list
    );
  }

  // ...
}

Basic Usage

import SmsRetriever from 'react-native-sms-retriever';

// Get the phone number (first gif)
 _onPhoneNumberPressed = async () => {
  try {
    const phoneNumber = await SmsRetriever.requestPhoneNumber();
  } catch (error) {
    console.log(JSON.stringify(error));
  }
 };

// Get the SMS message (second gif)
_onSmsListenerPressed = async () => {
  try {
    const registered = await SmsRetriever.startSmsRetriever();
    if (registered) {
      SmsRetriever.addSmsListener(event => {
        console.log(event.message);
        SmsRetriever.removeSmsListener();
      }); 
    }
  } catch (error) {
    console.log(JSON.stringify(error));
  }
};
About Phone

To get the phone number, use a real device. The SMS Retriever API doesn't work very well with emulators.

About SMS

The SMS Retriever API has some rules for message. A valid verification message might look like the following:

<#> Your Example app code is: 123ABC78
/SBnkJ8069Q

The <#> is required. The /SBnkJ8069Q is a hash string that identifies your app (in the case it's the hash of the example app). Too see how to generate the hash access this link. Alternatively, you can get your app's hash string with the AppSignatureHelper class.

Methods and Errors

requestPhoneNumber(): Promise<String>

Obtain the user's phone number (using the hint picket).

Error TypeError Message
ACTIVITY_NULL_ERROR_TYPEActivity is null.
ACTIVITY_RESULT_NOOK_ERROR_TYPEThere was an error trying to get the phone number.
CONNECTION_SUSPENENDED_ERROR_TYPEClient is temporarily in a disconnected state.
CONNECTION_FAILED_ERROR_TYPEThere was an error connecting the client to the service.
SEND_INTENT_ERROR_TYPEThere was an error trying to send intent.
UNAVAILABLE_ERROR_TYPEGoogle Play Services is not available.
UNSUPORTED_VERSION_ERROR_TYPEThe device version of Google Play Services is not supported.
startSmsRetriever(): Promise<Boolean>

Start to listen for SMS messages.

Error TypeError Message
TASK_FAILURE_ERROR_TYPETask failed.
UNAVAILABLE_ERROR_TYPEGoogle Play Services is not available.
UNSUPORTED_VERSION_ERROR_TYPEThe device version of Google Play Services is not supported.
addSmsListener(event: Function): Promise<Boolean>

Get the SMS content. Get the SMS content with: event.message.

Error ParamTypeDescription
extrasStringSent only when there was a problem getting the SMS content.
statusStringSent only when status is not OK or TIMEOUT.
timeoutStringSent only when status is equals to TIMEOUT.
removeSmsListener(): Void

Stop to listen for SMS messages.

Change-log

A brief summary of each React Native SMS Retriever release can be found on the releases.

License

This code is distributed under the terms and conditions of the MIT License.

Keywords

FAQs

Package last updated on 06 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc