Reputation: 279
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.
Upvotes: 0
Views: 1530
Reputation: 22189
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
Upvotes: 3