Expo ImagePicker.launchCameraAsync stopped because of User rejected permissions even though it's all granted

58 Views Asked by At

I've been building a small mobile app that takes pictures and store them somewhere specific. But, I can't find how to make Expo ImagePicker.launchCameraAsync work.

Here's my function:

const takeImage = async () => {
    try {
      const permission = await ImagePicker.getCameraPermissionsAsync();
      console.log(permission);
  
      if (permission.canAskAgain && permission.status === 'denied') {
        await ImagePicker.requestCameraPermissionsAsync();
      } else if (permission.status === 'canceled') {
        let toast = Toast.show('Vous avez refusé l\'accès à la caméra', {
          duration: Toast.durations.SHORT,
        });
        Linking.openSettings();
      } else if (permission.status === 'granted') {
        let toast = Toast.show('Permission accordée', {
          duration: Toast.durations.SHORT,
        });
  
        let cameraOptions = {
          mediaTypes: ImagePicker.MediaTypeOptions.All,
          allowsEditing: true,
          aspect: [4, 3],
          quality: 1,
        };
  
        let result = await ImagePicker.launchCameraAsync(cameraOptions);
  
        if (!result.canceled) {
          let toast = Toast.show('Image enregistrée avec succès', {
            duration: Toast.durations.SHORT,
          });
          setImage(result.assets[0].uri);
          let slug = string_to_slug(tableauName);
          let folderPath = FileSystem.documentDirectory + 'tableaux_bavards/' + slug;
          const newList = tableau.map((item) => {
            if (item.id === cellule) {
              const updatedItem = {
                ...item,
                image: folderPath + '/' + cellule + '.jpg',
                audio: folderPath + '/' + cellule + '.mp3',
              };
              return updatedItem;
            }
            return item;
          });
          if (image) {
            await copyFile(image, folderPath + '/' + cellule + '.jpg');
            setImage(null);
          }
        }
      }
    } catch (error) {
      console.error(error);
      // Handle errors here, such as displaying an error message to the user.
    }
  };

When logging permission I get the following:

{"canAskAgain": true, "expires": "never", "granted": true, "status": "granted"}

Which seems good, but later on when running ImagePicker.launchCameraAsync I get the following error:

[Error: Call to function 'ExponentImagePicker.launchCameraAsync' has been rejected.
→ Caused by: User rejected permissions]

Here is a part of the app.json file:

"permissions": [
    "android.permission.CAMERA",
    "android.permission.READ_EXTERNAL_STORAGE",
    "android.permission.WRITE_EXTERNAL_STORAGE",
    "android.permission.RECORD_AUDIO",
    "android.permission.FILESYSTEM_ACCESS"
  ],

I've been searching and trying stuff for a long-time now. I know there was some issues with it reported on Github, but after uninstalling Expo Go, making a reset of my development tablet, I can't get it to work.

Even with a preview APK.

Hope someone encountered that before and found a solution.

0

There are 0 best solutions below