I am new to React-Naive and trying to build an app that sends message through app using react-native-get-sms-android .
I am able to send and read SMS from inbox but there is no Event in the package to know if a new sms has been received.
Is there any Event or API in react native for this? I think I will have to use polling to check if a new sms has arrived.
You can either create your own native module or use react-native-android-sms-listener
to listen for the new messages similar to Whatsapp .
Manual Installation is provided in the docs
import SmsListener from 'react-native-android-sms-listener'
componentDidMount() {
this.subscription = SmsListener.addListener(message => {
console.info(message)
})
}
componentWillUnmount() {
this.subscription.remove()
}
where the contents are in the format
{
originatingAddress: string,
body: string
}
Also make sure that you need specific permissions to read SMS for android, check the permissions docs here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.