Issues on getting ImagePicker.launchCameraAsync to work

Hi, I’m currently working in React Native trying to open the camera to let the user add an image. I want to do this with the ImagePicker library and the function launchCameraAsync. The problem is that, when I try to execute the function, I get this error:

Error occurred while launching the camera: [Error: Call to function ‘ExponentImagePicker.launchCameraAsync’ has been rejected.
→ Caused by: User rejected permissions]

What’s weird is that, just before calling launchCameraAsync, i call requestCameraPermissionsAsync and it returns granted = true, meaning that the permissions to use the camera are provided.

This is my code:

  const openCamera = async () => {
    const status = await ImagePicker.requestCameraPermissionsAsync();
    console.log(status);
    try {
      let result = await ImagePicker.launchCameraAsync({
        mediaTypes: ImagePicker.MediaTypeOptions.Images,
        quality: 1,
        aspect: [4, 3],
      });
      if (!result.canceled) {
        console.log(result);
      }
    } catch (error) {
      console.log("Error occurred while launching the camera: ", error);
    }
  };

I really do not know how to proceed from here, and any help would be much appreciated!

I am also observing the same behavior. Some output confirms that permissions have been granted but the call to launchCameraAsync fails

 LOG  cameraStatus.granted: false
 LOG  requestCameraPermission
 LOG  permissionResult: {"canAskAgain": true, "expires": "never", "granted": true, "status": "granted"}
 LOG  launchCameraAsync
 WARN  Possible Unhandled Promise Rejection (id: 0):
Error: Call to function 'ExponentImagePicker.launchCameraAsync' has been rejected.
→ Caused by: User rejected permissions
construct@[native code]
construct@[native code]
_construct@http://192.168.1.214:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false:19240:28
Wrapper@http://192.168.1.214:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false:19202:25
construct@[native code]
_createSuperInternal@http://192.168.1.214:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false:94969:322

I haven’t been able to solve this. However, I did test my app on other devices and the issue does not happen to them, so I assume the problem is the device, not the code. I tried reinstalling expo go on the device I have the issue with no succes and I’m really unable to see where the problem is. If you can, try to test your app on other devices to see if the issue persists, and I’m guessing you won’t see get the error

same here. happening to a considerable large part of our user base but not to everybody. happened after migrating from SDK 45 to SDK 47.

Looking this issue below, it seems that it was fixed on SDK 47. any workaround to make it work on SDK 48?

I think it has to do with the memory of the device, free some Space on the device and start the app again.

I just run on expo Go simulator, what do you mean with free some Space on the device?
any clue? because i have run the expo start -c but still error

I don’t think that’s the issue since my device has plenty of memory remaining (40gb) and I still get the error.

I gave ImagePicker.launchCameraAsync() a try in one of my apps. This app is Android only (because I’m using an image manipulation processing that is written in Java, so is only available for Android), so I haven’t tested it on iOS.

I found the documentation lacking and went looking for examples on GitHub. I tried using the useCameraPermissions() hook, but was getting errors saying something about different numbers of hooks being detected, implying that I was conditionally calling one or more hooks. As far as I know this was not true.

In the end I took out all permission handling code and just called ImagePicker.launchCameraAsync(). When I click on the button that makes that call, I get prompted to allow Camera permissions and after that I get prompted to allow access to file/photos on the device (from memory. I can’t remember the exact wording.)

So I’m not sure what the story is, but it seems to me that maybe you don’t actually have to do anything with permissions and the user will be prompted when the call to launchCameraAsync() is made. :man_shrugging: I have not tested this extensively.

I’d be interested in more insight into this behaviour or the requirements.

I’m also not really sure why permissions are required at all. I don’t need permissions to use launchImageLibraryAsync() because as far as I understand it, the app is just calling a system image picker to return an image. Conceptually this seems the same as calling some system camera component to return an image.

Is it perhaps because launchCameraAsync() is not just calling some built-in/system camera component?

As an aside, I don’t want to record video/audio, but by default the app has microphone listed under permissions in the app, although it’s turned off. I poked around in the source code and found that you can actually do the following to remove it completely:

app.json:

    "plugins": [
      [
        "expo-image-picker",
        {
          "microphonePermission": false
        }
      ]
    ]

This is undocumented.

let permissionResult =
      await ImagePicker.requestMediaLibraryPermissionsAsync();
    if (permissionResult.granted === false) {
      alert("Camera access is required");
      return;
    }

try this