I am using react-native-camera to scan barcodes. On iOS, where I started developing, everything works well as expected. On Android though, it will just not fire onBarcodeRead
when a barcode is focused with the camera.
The relevant piece of code is the following:
<View style={styles.container}>
<RNCamera
ref={(ref) => {
setCamera(ref);
}}
aspect={1}
style={styles.preview}
type={RNCamera.Constants.Type.back}
flashMode={RNCamera.Constants.FlashMode.on}
captureAudio={false}
onBarCodeRead={processBarcode}
androidCameraPermissionOptions={{
title: 'Permission to use camera',
message: 'We need your permission to use your camera',
buttonPositive: 'Ok',
buttonNegative: 'Cancel',
}}>
<View>{mainInteractionElement}</View>
</RNCamera>
</View>
The function processBarcode
will just not be fired on Android. I have already read through all (old) answers around the barcode scanning not working on Android but nothing described helped me (e.g. upgrading to the latest version, setting the aspect ratio, ...).
Does anyone maybe have a solution?
Thanks and best regards
Actually I did not get it running. In the end, I decided to use onBarCodeRead
on iOS and onGoogleVisionBarcodesDetected
on Android. That was the only way I got it running on both platforms.