Fix Camera permissions and enable front camera fallback on Android
This commit is contained in:
LFS
BIN
Binary file not shown.
@@ -8,6 +8,7 @@ import {
|
|||||||
Modal,
|
Modal,
|
||||||
TextInput,
|
TextInput,
|
||||||
TouchableWithoutFeedback,
|
TouchableWithoutFeedback,
|
||||||
|
PermissionsAndroid,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { CameraView, useCameraPermissions } from 'expo-camera';
|
import { CameraView, useCameraPermissions } from 'expo-camera';
|
||||||
import * as FileSystem from 'expo-file-system';
|
import * as FileSystem from 'expo-file-system';
|
||||||
@@ -131,7 +132,24 @@ export default function CameraScreen({
|
|||||||
if (permission && !permission.granted && permission.canAskAgain) {
|
if (permission && !permission.granted && permission.canAskAgain) {
|
||||||
requestPermission();
|
requestPermission();
|
||||||
}
|
}
|
||||||
}, []);
|
|
||||||
|
// Specifically for ausbc native library which needs these at runtime
|
||||||
|
if (Platform.OS === 'android') {
|
||||||
|
const requestAndroidPerms = async () => {
|
||||||
|
try {
|
||||||
|
const granted = await PermissionsAndroid.requestMultiple([
|
||||||
|
PermissionsAndroid.PERMISSIONS.CAMERA,
|
||||||
|
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
|
||||||
|
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
|
||||||
|
]);
|
||||||
|
logger.log('Android Permissions:', JSON.stringify(granted));
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('Failed to request Android permissions', err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
requestAndroidPerms();
|
||||||
|
}
|
||||||
|
}, [permission]);
|
||||||
|
|
||||||
// 2. Check if a USB camera is connected.
|
// 2. Check if a USB camera is connected.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -400,29 +418,27 @@ export default function CameraScreen({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// On iOS we need the expo-camera permission, on Android we bypass it since we use USB
|
// Show permission block if built-in camera has no permission AND USB is not connected
|
||||||
if (Platform.OS !== 'android') {
|
if (!permission) {
|
||||||
if (!permission) {
|
return (
|
||||||
return (
|
<View style={styles.container}>
|
||||||
<View style={styles.container}>
|
<Text style={styles.infoText}>Berechtigungen werden geladen...</Text>
|
||||||
<Text style={styles.infoText}>Berechtigungen werden geladen...</Text>
|
</View>
|
||||||
</View>
|
);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!permission.granted && !isUsbConnected) {
|
if (!permission.granted && !isUsbConnected) {
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Text style={styles.infoText}>Wir benötigen deine Erlaubnis, um die Kamera anzuzeigen</Text>
|
<Text style={styles.infoText}>Wir benötigen deine Erlaubnis, um die Tablet-Kamera anzuzeigen</Text>
|
||||||
<TouchableOpacity style={styles.btn} onPress={requestPermission}>
|
<TouchableOpacity style={styles.btn} onPress={requestPermission}>
|
||||||
<Text style={styles.btnText}>Erlaubnis erteilen</Text>
|
<Text style={styles.btnText}>Erlaubnis erteilen</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
<TouchableOpacity style={[styles.btn, styles.cancelBtn]} onPress={handleLocalCancel}>
|
<TouchableOpacity style={[styles.btn, styles.cancelBtn]} onPress={handleLocalCancel}>
|
||||||
<Text style={styles.btnText}>Zurück</Text>
|
<Text style={styles.btnText}>Zurück</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const renderContent = () => {
|
const renderContent = () => {
|
||||||
@@ -628,7 +644,7 @@ export default function CameraScreen({
|
|||||||
{/* Camera Preview Background */}
|
{/* Camera Preview Background */}
|
||||||
<View style={styles.previewContainer}>
|
<View style={styles.previewContainer}>
|
||||||
<View style={styles.cameraWrapper}>
|
<View style={styles.cameraWrapper}>
|
||||||
{Platform.OS === 'android' ? (
|
{Platform.OS === 'android' && isUsbConnected ? (
|
||||||
<UsbCameraView
|
<UsbCameraView
|
||||||
ref={usbCameraRef}
|
ref={usbCameraRef}
|
||||||
style={[styles.cameraPreview, { position: 'absolute', opacity: 1, zIndex: 10 }]}
|
style={[styles.cameraPreview, { position: 'absolute', opacity: 1, zIndex: 10 }]}
|
||||||
|
|||||||
Reference in New Issue
Block a user