Reputation: 86
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
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.
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.
Upvotes: 0
Reputation: 597
Instead of pause preview method. Try it with skipProcessing to false inside option object
Upvotes: 0