andreyvital / react-native-android-sms-listener

Allows you to listen for incoming SMS messages using React Native
MIT License
358 stars 99 forks source link

Emit receive sms many time. #58

Closed chelx closed 3 years ago

chelx commented 3 years ago

My code: ` import SmsListener from 'react-native-android-sms-listener'

SmsListener.addListener( message => { console.log("add:", message) })`

And the result:

LOG  add: {"body": "Android is always a sweet treat!000000", "originatingAddress": "123", "timestamp": 1617089036000}
 LOG  add: {"body": "Android is always a sweet treat!000000", "originatingAddress": "123", "timestamp": 1617089036000}
 LOG  add: {"body": "Android is always a sweet treat!000000", "originatingAddress": "123", "timestamp": 1617089036000}
 LOG  add: {"body": "Android is always a sweet treat!000000", "originatingAddress": "123", "timestamp": 1617089036000}
 LOG  add: {"body": "Android is always a sweet treat!000000", "originatingAddress": "123", "timestamp": 1617089036000}
 LOG  add: {"body": "Android is always a sweet treat!000000", "originatingAddress": "123", "timestamp": 1617089036000}
 LOG  add: {"body": "Android is always a sweet treat!111111", "originatingAddress": "123", "timestamp": 1617089045000}
 LOG  add: {"body": "Android is always a sweet treat!111111", "originatingAddress": "123", "timestamp": 1617089045000}
 LOG  add: {"body": "Android is always a sweet treat!111111", "originatingAddress": "123", "timestamp": 1617089045000}
 LOG  add: {"body": "Android is always a sweet treat!111111", "originatingAddress": "123", "timestamp": 1617089045000}

p/s: I run this code on the android emulator

chelx commented 3 years ago

This happen because "addListener" execute every render screen.