react-native-get-sms-android icon indicating copy to clipboard operation
react-native-get-sms-android copied to clipboard

Permision denied before send SMS in android

Open ajiehatajie opened this issue 6 years ago • 3 comments

How check permission before send SMS ? because log is error if permissions denied in android 7.

ajiehatajie avatar Sep 14 '18 07:09 ajiehatajie

@ajiehatajie try this:

import { PermissionsAndroid, Alert } from 'react-native';

async componentDidMount() {
  try {
    let granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.SEND_SMS, {
        title: 'Send SMS',
        message: 'Need access to send sms',
      },
    );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log('SEND_SMS permissions granted', granted);
    } else {
      Alert.alert('SEND_SMS permissions denied');
      console.log('SEND_SMS permissions denied');
    }
  } catch (err) {
    Alert.alert(err);
  }
};

olbesp avatar Dec 28 '18 20:12 olbesp

Thanks for this. @olbesp. Hopefully, I'll get to integrating this into the docs and maybe getting the package to fail gracefully.

briankabiro avatar Feb 11 '19 10:02 briankabiro

I created PR #84, which adds the code from @olbesp to the example code, which is in the readme file.

Bilal-Abdeen avatar Apr 23 '21 01:04 Bilal-Abdeen