briankabiro / react-native-get-sms-android

React Native module to get messages on an Android device
MIT License
137 stars 68 forks source link

Filter not working for address #46

Closed paurakhsharma closed 5 years ago

paurakhsharma commented 5 years ago

This is how my dependencies looks like

"dependencies": {
    "react": "16.8.1",
    "react-native": "0.61.2",
    "react-native-get-sms-android": "^2.0.0"
  },

I have the following filter

var filter = {
          box: 'inbox', // 'inbox' (default), 'sent', 'draft', 'outbox', 'failed', 'queued', and '' for all
          // the next 4 filters should NOT be used together, they are OR-ed so pick one
          read: 1, // 0 for unread SMS, 1 for SMS already read
          // _id: 1061, // specify the msg id
          address: 'NICA_ALERT', // sender's phone number
          // body: 'Your 166##24001 has been Debited', // content to match
          // the next 2 filters can be used for pagination
          indexFrom: 0, // start from index 0
          maxCount: 100, // count of SMS to return each time
        };

I want to get only the SMS send from NICA_ALERT but I get other messages that is not set by NICA_ALERT

Here is how I have implemented the code

await SmsAndroid.list(
          JSON.stringify(filter),
          (fail) => {
            console.log('Failed with this error: ' + fail);
          },
          (count, smsList) => {
            var arr = JSON.parse(smsList);
            setSMSList(arr)
          },
        );

Expected

To get only messages from NICA_ALERT

Actual

Got messages from other senders aswell.

briankabiro commented 5 years ago

Hi @paurakhsharma.

Thanks for including the code that you are using.

Could you try omitting the read: 1 and using address: 'NICA_ALERT' only? Something like this:

var filter = {
          box: 'inbox', // 'inbox' (default), 'sent', 'draft', 'outbox', 'failed', 'queued', and '' for all
          // the next 4 filters should NOT be used together, they are OR-ed so pick one
          // _id: 1061, // specify the msg id
          address: 'NICA_ALERT', // sender's phone number
          indexFrom: 0, // start from index 0
          maxCount: 100, // count of SMS to return each time
        };

This is because of this condition when creating the filter -- the next 4 filters should NOT be used together, they are OR-ed so pick one

paurakhsharma commented 5 years ago

Sorry, I didn't read the commented documentation carefully. It works. Thank you so much.

briankabiro commented 5 years ago

No worries at all. :)