Package Exports
- @ernestbies/react-native-android-sms-listener
- @ernestbies/react-native-android-sms-listener/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ernestbies/react-native-android-sms-listener) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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