On a specific device (Samsung Galaxy S9 with Android 9), when I try to open the camera through ExponentImagePicker, I get the following error:
Error: Call to function 'ExponentImagePicker.launchCameraAsync' has been rejected.
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property cameraLauncher has not been initialized
On an Android 9 emulator it works, and also for newer API version emulators. This was working previously, but seems to have stopped working after updating react native and other libraries.
Anything I can do about it?
Code:
import * as ImagePicker from 'expo-image-picker';
const MediaSelector: React.FC<Props> = (props) => {
const open = async () => {
const permissions = await ImagePicker.requestCameraPermissionsAsync();
if (!permissions.granted) return Alert.alert("permission denied!"))
const config: ImagePicker.ImagePickerOptions = {
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
allowsMultipleSelection: false,
exif: false,
aspect: [1, 1],
}
try {
const result = await ImagePicker.launchCameraAsync(config);
} catch (error) {
console.log(error)
Alert.alert("error!")
return
}
}
return <Pressable style={styles.container} onPress={open}>
<ImageView img={props.image}/>
</Pressable/>
}
versions:
"react": "18.0.0",
"expo-image-picker": "~13.3.1",
"react-native": "0.69.6",
I had the same issue, and for some reason using getCameraPermissionsAsync() fixed the issue - whereas requestCameraPermissionsAsync() on its own would cause launchCameraAsync() to be rejected on Android devices.
See the following:
let permissionResult = await ImagePicker.getCameraPermissionsAsync();
if(permissionResult.status !== 'granted') {
permissionResult = await ImagePicker.requestCameraPermissionsAsync();
}
if(permissionResult.status !== 'granted') {
alert("You must turn on camera permissions to record a video.");
}
else {
let result = await ImagePicker.launchCameraAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Videos,
allowsEditing: true,
aspect: [3, 4],
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With