I'm using react-native-image-crop-picker
to upload image but I'm getting error that I didn't allow permission please allow it
but I already allow the permission but still getting same error, I used same code that I used in other apps but I'm getting error in that app
here is my code for image picker
State
const [state, setState] = useState({
imgObj: '',
original: '',
});
premission
export const androidCameraPermission = () =>
new Promise(async (resolve, reject) => {
try {
if (Platform.OS === 'android' && Platform.Version > 22) {
const granted = await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.CAMERA,
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
]);
console.log(granted, 'hte aojfoj');
if (
granted['android.permission.CAMERA'] !== 'granted' ||
granted['android.permission.WRITE_EXTERNAL_STORAGE'] !== 'granted' ||
granted['android.permission.READ_EXTERNAL_STORAGE'] !== 'granted'
) {
showError("Don't have required permission.Please allow permissions");
return resolve(false);
// alert(strings.DO_NOT_HAVE_PERMISSIONS_TO_SELECT_IMAGE);
}
return resolve(true);
}
return resolve(true);
} catch (error) {
return resolve(false);
}
});
picker
const onImageChange = async () => {
const permissionStatus = await androidCameraPermission();
if (permissionStatus || Platform.OS === 'ios') {
Alert.alert(
'Profile Picture',
'Choose an option',
[
{text: 'Camera', onPress: onCamera},
{text: 'Gallery', onPress: onGallery},
{text: 'Cancel', onPress: () => {}},
],
{cancelable: true},
);
}
};
const onGallery = async () => {
try {
let image = await ImagePicker.openPicker({
width: 300,
height: 400,
multiple: false,
cropping: true,
mediaType: 'photo',
});
console.log('Image path', image);
imageUpload(image.path);
} catch (error) {
console.log(error);
}
};
const onCamera = async () => {
try {
let image = await ImagePicker.openCamera({
width: 100,
height: 100,
useFrontCamera: true,
multiple: false,
mediaType: 'photo',
});
console.log('Image path', image);
imageUpload(image.path);
} catch (error) {
console.log('Image Picker error: ', error);
}
};
view
<TouchableOpacity
style={{
alignItems: 'center',
justifyContent: 'center',
marginTop: moderateScaleVertical(33),
}}
onPress={onImageChange}>
{!imgObj ? (
<Image source={imagePath.profile_pic} />
) : (
<Image source={{uri: imgObj}} />
)}
</TouchableOpacity>
I always use same code in every app but why I'm getting error in that app?
question from:
https://stackoverflow.com/questions/65713640/react-native-you-dont-have-permission-please-allow-it-while-uploading-image