Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if user has granted camera permission in React Native Android?

Right after the app launches, I am getting permission to use Camera from the user. But before opening camera if I check if the user has granted camera permission or not, I get the response as "false" even when it is allowed.

Here is my code:

PermissionsAndroid.check('camera').then(response => {
            if (response === true){
                //Open scanner
            }
            else if (response === false){
                Alert("Please enable camera permission in device settings.")
            }
        })
like image 300
Gautham Raj Ayyapparaj Avatar asked Dec 18 '22 22:12

Gautham Raj Ayyapparaj


1 Answers

Please try as following:

PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.CAMERA).then(response => { ..

and not

PermissionsAndroid.check('camera').then(response => { ..
like image 72
crystal_17 Avatar answered Mar 08 '23 22:03

crystal_17