Android 8.1 Crashes trying to get image from ImagePicker Expo 31.0.0


#1

I ask for both permissions from the user Permissions.CAMERA and Permissions.CAMERA_ROLL.

On android 8.1 CAMERA_ROLL comes back ‘undefined’. CAMERA is granted.

Trying to start the imagePicker crashes with no error. Here is the code. The permissions are asked on mounting and then take takePhoto is called by a button:

async componentDidMount() {
    console.log('camera screen mounted');
    const { status } = await Permissions.askAsync(Permissions.CAMERA);
    const { status_roll } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
    console.log('status and status camera is ' , status)
    console.log('status and status roll is ' , status_roll)
    if (status !== 'granted') {
      // TODO: Show message in alert bar
      alert('Please grant app access to the camera so you can upload your photo.');
    }
    if (status_roll !== 'granted') {
      // TODO: Show message in alert bar
      alert('Please grant app access to the camera roll so you can upload your photo.');
    }
    //this.takePhoto();
  }

  takePhoto = async () => {
    console.log('take photo called')
    const pickerResult = await ImagePicker.launchCameraAsync({
      allowsEditing: true,
      aspect: [4, 4],
      exif: true,
    });
    console.log('picker result is ' , pickerResult);
    this.handleImagePicked(pickerResult);
  };

Also this is a Moto X4


#2

Hey @nickjuntilla,

status_roll is not a property returned by the Permissions.askAsync object so you’re trying to de-structure something that isn’t there and thus getting undefined. You could either separate the camera roll askAsync function into a separate function or you could do something like const cameraRollPermission = await Permissions.askAsync(Permissions.CAMERA_ROLL) and then use cameraRollPermission.status to check if it’s granted or denied.

Cheers,

Adam


#3

Ok I updated the camera roll permission to this:

const cameraRollPermission = await Permissions.askAsync(Permissions.CAMERA_ROLL);
const status_roll = cameraRollPermission.status;

Now they both appear to be ‘granted’, but it still crashes on MOTO X4 Android 8.1 on

 const pickerResult = await ImagePicker.launchCameraAsync({

#4

I meant to address that the change wasn’t going to fix the crash, but was just a necessary change. My apologies!

Things certainly seems to be a bug, could you by chance create an issue here: https://github.com/expo/expo/issues with all the relevant information and ideally a Snack to repro it or a github repo works too! This one may prove difficult to debug given that it’s specific to one device. Have you gotten the chance to investigate if this has happened on any other Android devices?


#5

Thanks, I submit this issue: https://github.com/expo/expo/issues/2925