2 years ago

#73941

test-img

Estro

PermissionsAndroid not returning anything

Hello I'm trying to use PermissionsAndroid to ask my user to use the Camera. Following the guide (https://reactnative.dev/docs/permissionsandroid) I did this :

const requestCameraPermission = async () => {
  try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.CAMERA,
      {
        title: "Cool Photo App Camera Permission",
        message:
          "Cool Photo App needs access to your camera " +
          "so you can take awesome pictures.",
        buttonNeutral: "Ask Me Later",
        buttonNegative: "Cancel",
        buttonPositive: "OK"
      }
    );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log("You can use the camera");
    } else {
      console.log("Camera permission denied");
    }
  } catch (err) {
    console.warn(err);
  }

It works well and asking the Permission to use it but unfortunately it doesn't go further, even if I set a console.log before the if (granted === PermissionsAndroid.RESULTS.GRANTED) it doesn't show anything in the console in an emulator.

I tried the snack on the link above but it doesn't show anything in the console in emulator but with a real device it shows things in the console. So my question is : Is it normal that it doesn't work on emulator or am I missing something ?

Thanks

react-native

android-permissions

0 Answers

Your Answer

Accepted video resources