Listen for incoming SMS messages in React Native!
ekxh8810
9年前
来自: https://github.com/CentaurWarchief/react-native-android-sms-listener
react-native-android-sms-listener
An utility that allows you to add listeners for incoming SMS messages.
Example
import SmsListener from 'react-native-android-sms-listener' SmsListener.addListener(message => { console.info(message) })
The contents of message object will be:
{ originatingAddress: string, body: string }
Installation
$ npm install --save react-native-android-sms-listener
...and all you need to do to use this so-called utility is:
android/settings.gradle
include ':ReactNativeAndroidSmsListener' project(':ReactNativeAndroidSmsListener').projectDir = new File( rootProject.projectDir, '../node_modules/react-native-android-sms-listener/android' )
android/app/build.gradle
dependencies { compile project(':ReactNativeAndroidSmsListener') // (...) }
import com.centaurwarchief.smslistener.SmsListener; @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), new SmsListener(this) // (...) ); }