ImagePicker.requestCamera asking for MediaLibrary permissions too on Android.

  1. SDK Version: Android API 31
  2. Platforms(Android/iOS/web/all): Android

I’m having a problem with rejected permissions when trying to use ImagePicker.launchCameraAsync.
This is the function that I’m using that works fine with iOS when handling denied permissions: it shows an alert that redirects the user to the settings app to enable permissions. My problem is when I tried to do the same on Android. It asks for both Camera and Library permissions. When I reject the camera permission it works just as expected (the alert shows up and redirects me to the settings) but when I reject the second permission (media) I got an error “Unhandled promise rejection Error: User rejected permissions”. Am I doing something wrong or I do need to handle both permissions on Android when trying to use the camera?

 async function handleTakingNewPicture() {
    if (!hasCameraPermission) {
      const { status } = await ImagePicker.requestCameraPermissionsAsync();

      if (status !== 'granted') {
        Alert.alert(
          'Alert',
          'Some alert',
          [{ text: 'Ok', onPress: () => Linking.openSettings() }],
        );
        return;
      }
    }
    
  const image = await ImagePicker.launchCameraAsync({
          allowsEditing: true,
          quality: 0.5,
          base64: true,
        });

    console.log('IMAGE', image);
}

Hi @gustavoccintrao

The launchCameraAsync() requires both Camera and Camera Roll permission on Android. Yes, you will need to handle the second permission too using ImagePicker.requestMediaLibraryPermissionsAsync().

You can read more about all permissions required at ImagePicker docs.

2 Likes

Thank you! It worked as expected :smiley:

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.