Patrick O'Neill
Patrick O'Neill

Reputation: 86

expo-camera takePictureAsync() not working on Android

I recently updated several lines of code in a managed expo project, unrelated to the camera functionality. It still works fine on iOS, only Android does not work. I had released a previous version one month ago that worked well. When I revert back to the old commit from then, though, it also does not work on Android (iOS fine).

There is no issue launching the camera, etc. Rather, the issue occurs at takePictureAsync, which hangs and then does not return anything.

const snapPic = async () => {
    const { status } = await Camera.getCameraPermissionsAsync();
    if (status != 'granted') {
        alert('Please grant access to camera and retry.');
        await Camera.requestCameraPermissionsAsync();
        return;
    }
    const options = { quality: 0.1 };
    const photo = await this.camera.takePictureAsync(options);
    this.camera.pausePreview();
    this.setState({imageSource: photo.uri});
};

<Camera style={styles.cameraBox} ref={ref => {this.camera = ref}} />

Please let me know what other information I can provide, if necessary. Thanks in advance!

Upvotes: 6

Views: 1864

Answers (2)

Jack
Jack

Reputation: 256

I had the exact same issue on the android emulator when using VirtualScene or Webcam0. On a physical android device everything works fine, but on the emulator the camera would freeze when I took a photo, hanging on takePictureAsync.

What worked for me:

Switch the camera option to "Emulated" in the device (AVD) settings. In android studio, click the edit button next to the device you are using, click on advanced settings, scroll down to Camera, and change either the front or back camera (whichever you are experiencing the issue with) to the "Emulated" option.

enter image description here

Upvotes: 0

Manish Arora
Manish Arora

Reputation: 597

Instead of pause preview method. Try it with skipProcessing to false inside option object

Upvotes: 0

Related Questions