Expo SDK Version: 42.0.0
Expo BarCodeScanner version: ~10.2.2
Platforms: Android phone & Android tablet
I have an app that reads barcodes and posts to a database. The app runs fine of both emulated Android phones and real Android phones. I have not tried on iOS yet. But the issue is, that when I try to run it on an emulated tablet, it is like the onBarCodeScanned function is never called. The camera just lingers on a barcode and does not trigger the Alert I have written as it does on a phone.
The code for the camera is close to the showcased code from Expo and with some additions for a custom alert box.
I hope someone can help me figuring this out.
Thanks
const [hasPermission, setHasPermission] = useState(null);
const [scanned, setScanned] = useState(false);
const [bottleID, setBottleID] = useState('')
const [equipmentID, setEquipmentID] = useState('')
const sender = props.route.params.sender
useEffect(() => {
(async () => {
const { status } = await BarCodeScanner.requestPermissionsAsync()
setHasPermission(status === 'granted')
})()
}, [])
const scannedAlertBox = () => {
if (sender === 'equipment') {
Alert.alert(
"Equipment scanned",
"Please continue or scan again",
[
{
text: "Scan again",
onPress: () => setScanned(false)
},
{
text: "Continue",
onPress: () => props.navigation.navigate("Sampling", { equipmentID: equipmentID })
}
]
)
}
else {
Alert.alert(
"Bottle scanned",
"Please continue or scan again",
[
{
text: "Scan again",
onPress: () => setScanned(false)
},
{
text: "Continue",
onPress: () => props.navigation.navigate("Sampling", { bottleID: bottleID })
}
]
)
}
}
const handleBarCodeScanned = ({ data }) => {
if (sender === 'equipment') {
setEquipmentID(data)
}
else {
setBottleID(data)
}
if (!(bottleID === '' && equipmentID === '')) {
setScanned(true)
scannedAlertBox()
}
}
if (hasPermission === null) {
return <Text style={{ justifyContent: 'center', alignContent: 'center', alignSelf: 'center', alignItems: 'center' }} >Requesting for camera permission</Text>
}
if (hasPermission === false) {
return <Text>No access to camera</Text>
}
if (sender === 'equipment') {
return (
<View style={styles.container}>
<BarCodeScanner onBarCodeScanned={scanned ? undefined : handleBarCodeScanned} style={StyleSheet.absoluteFillObject} />
{scanned}
</View>
)
}
else {
return (
<View style={styles.container}>
<BarCodeScanner onBarCodeScanned={scanned ? undefined : handleBarCodeScanned} style={StyleSheet.absoluteFillObject} />
{scanned}
</View>
)
}
} ```