Skip to content

ernestbies/react-native-android-sms-listener

 
 

Repository files navigation

react-native-android-sms-listener

A utility that allows you to listen for incoming SMS messages (working in background).

Example

import SmsListener from '@ernestbies/react-native-android-sms-listener'

SmsListener.addListener(message => {
  console.info(message)
})

The contents of message object will be:

{
  originatingAddress: string,
  body: string,
  timestamp: number
}

SmsListener#addListener returns a CancellableSubscription so if you want to stop listening for incoming SMS messages you can simply .remove it:

let subscription = SmsListener.addListener(...)

subscription.remove()

In recent versions of Android you might also have to ask for permissions READ_SMS and RECEIVE_SMS:

async function requestReadSmsPermission() {
  try {
    await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.READ_SMS,
    );

    await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.RECEIVE_SMS,
    );
  } catch (err) {}
}

Installation

$ npm install --save @ernestbies/react-native-android-sms-listener

About

Allows you to listen for incoming SMS messages using React Native.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 90.5%
  • JavaScript 9.5%