androidiosreact-nativesmsread-sms

Read ALL SMS in inbox or Send it to Server in React NATIVE


I am building an app that requires the functionality of reading SMS from the inbox. It's a kind of app that Microsoft built known as SMS organizer. I'm trying to build it for the local crowd and I'm using react-native to do the same. I read many libraries but none seem to be helpful or informative for my cause.

Anyone has any idea for how I can accomplish the same. PS- I'm aiming to do it for both androids as well as ios.


Solution

  • True- We cannot read sms in IOS devices.

    For Android, I found a library that helps to achieve this.

    import SmsAndroid from 'react-native-get-sms-android'; 
    
    var filter = {
      box: 'inbox',
    };
    
    const Readsms_list = async () => {
      SmsAndroid.list(
        JSON.stringify(filter),
        (fail) => {
          console.log('Failed with this error: ' + fail);
        },
        (count, smsList) => {
          console.log('Count: ', count);
          console.log('List: ', smsList);
          var arr = JSON.parse(smsList);
    
          arr.forEach(function (object) {
        // 'Object: ' +
        console.log(object);
        // console.log('-->' + object.date);
        // console.log('-->' + object.body);
      });
    },
    

    ); };

    This helps in reading all the SMS from the device.