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 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
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. 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: