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

it doesn't work for me at all #56

Closed hamidashoor closed 3 years ago

hamidashoor commented 3 years ago

i installed the package of react-native-android-sms-listener and this is my code in a Function :

  SmsRetriever.addSmsListener(event => {
          alert(event.message);
          SmsRetriever.removeSmsListener();
        }); 

and when I press a bottom, this code runs...

and i didn't get any alert in my application

lucasalexandre-cc commented 3 years ago

Here is not working too.

function getPermission() {
    return PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.READ_SMS,
      {
        title: "Ola",
        message: "Permissão para ver seu sms rss."
      }
    );
  }

  async function listenSms() {
    const resp = await getPermission();
    console.log(resp);
    const lister = SmsListener.addListener(message => {
      console.log(message);
      addMessage(message.body);
    });
    setSmsListner(lister);
  }

I receive granted permission, test send sms but the listener is not working.

lucasalexandre-cc commented 3 years ago

Here is not working too.

function getPermission() {
    return PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.READ_SMS,
      {
        title: "Ola",
        message: "Permissão para ver seu sms rss."
      }
    );
  }

  async function listenSms() {
    const resp = await getPermission();
    console.log(resp);
    const lister = SmsListener.addListener(message => {
      console.log(message);
      addMessage(message.body);
    });
    setSmsListner(lister);
  }

I receive granted permission, test send sms but the listener is not working.

I solve this problem, sorry. I only need to ask for "RECEIVE_SMS" permission too.

async function getPermission() {
    await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.READ_SMS,
      {
        title: "Ola",
        message: "Permissão para ver seu sms rss."
      }
    );

    await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.RECEIVE_SMS, {
      title: 'Receive SMS',
      message: 'Need access to receive sms, to verify OTP'
    }
    );
  }
novonimo commented 3 years ago

I solve this problem, sorry. I only need to ask for "RECEIVE_SMS" permission too.

async function getPermission() {
    await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.READ_SMS,
      {
        title: "Ola",
        message: "Permissão para ver seu sms rss."
      }
    );

    await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.RECEIVE_SMS, {
      title: 'Receive SMS',
      message: 'Need access to receive sms, to verify OTP'
    }
    );
  }

don't forget to add READT_SMS and RECEIVE_SMS permissions to your AndroidManifest.xml too.

sudo-vaibhav commented 3 years ago

can we close this issue now since the problem is solved?