Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Permissions not printing the status

I am using React Native version 42 and asking permissions as below. But after allowing or denying the permissions, I am not seeing the status in console. According to documentation https://facebook.github.io/react-native/docs/permissionsandroid.html they say we can see the status in console. Can anybody help me what I am doing wrong. I want to print the status of granted but the line itself is not getting called.

componentDidMount() {       
this.requestPermissions();
}

async requestPermissions() {

    try {  
        const granted = await PermissionsAndroid.requestMultiple([PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE, PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE])
        console.log("permissions status: " +JSON.stringify(granted));
    } catch (err) {
        console.warn(err)
    }
}
like image 847
Praneeth Avatar asked Jan 05 '23 07:01

Praneeth


1 Answers

PermissionAndroid.requestMultiple returns a promise with permission status. Try like this

PermissionsAndroid.requestMultiple([PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE, PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE]).then((result) => {
  console.log('result', result);
})
like image 170
Hariks Avatar answered Jan 13 '23 07:01

Hariks