I'm experiencing an issue with react-native-image-picker on an Android 11 device where, after taking a photo, the application does not respond to the tick (checkmark) icon being pressed to accept the image. The camera interface allows me to cancel the camera or retake the image without any problems, but pressing the tick to accept and save the image does not proceed as expected. This issue does not occur on devices running versions of Android older than 11, where the image picker works as intended.
Here's a snippet of the code I'm using to launch the camera:
const requestGalleryPermission = async () => {
try {
const permissions = [
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
PermissionsAndroid.PERMISSIONS.CAMERA,
];
const granted = await PermissionsAndroid.requestMultiple(permissions);
const storageGranted = granted[PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE] === PermissionsAndroid.RESULTS.GRANTED;
const writeGranted = granted[PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE] === PermissionsAndroid.RESULTS.GRANTED;
const cameraGranted = granted[PermissionsAndroid.PERMISSIONS.CAMERA] === PermissionsAndroid.RESULTS.GRANTED;
if (storageGranted && cameraGranted && writeGranted) {
console.log('Both read storage and camera permissions granted');
return true;
} else {
console.log('Read storage or camera permission denied');
return false;
}
} catch (err) {
console.warn('Permission request error:', err);
return false;
}
};
export const handleCameraLaunch = async (launchCameraEvent) => {
const options = {
mediaType: 'photo',
includeBase64: true,
maxHeight: 2000,
maxWidth: 2000,
};
const permission = requestGalleryPermission();
if (permission) {
await launchCamera(options, response => {
if (response.didCancel) {
console.log('User cancelled camera');
} else if (response.error) {
console.log('Camera Error: ', response.error);
} else {
console.log('Taking photo');
launchCameraEvent(response);
}
});
}
};
I have ensured that all necessary permissions are granted, and the AndroidManifest.xml includes permissions for CAMERA and READ_EXTERNAL_STORAGE, as well as adding android:requestLegacyExternalStorage="true". I'm targeting API level 30 (Android 11) and have tested on multiple devices. The issue seems to persist specifically on Android 11.
I've come across suggestions online to override onActivityResult as a potential fix but am unsure how to proceed with that in a React Native context, or if that's even the right approach.
Has anyone faced a similar issue or can provide insight into how to resolve this problem? Any help or guidance would be greatly appreciated.