Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

javascript - React Native, you don't have permission please allow it while uploading image

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

enter image description here

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

enter image description here

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...