0

我正在尝试将捕获的图片保存到我的设备库并将其取回以显示在我的项目中。但这里的平均问题是权限拒绝问题。我已经用这些设置了“AndroidManifest.xml”:但我仍然收到错误,这是我的代码....

render() {
    return (
      <View style={styles.container}>
          <RNCamera
            ref = {ref=>{
                this.camera=ref;
            }}
            style={styles.preview}
            flashMode={this.state.flashon}
            type={this.state.backCamera ? RNCamera.Constants.Type.back : RNCamera.Constants.Type.front} 
            captureAudio={this.state.captureAudio}
            androidCameraPermissionOptions={{
              title: 'Vocajam needs ermission to use camera',
              message: 'We need your permission to use your camera',
              buttonPositive: 'Ok',
              buttonNegative: 'Cancel',
            }}
          >
              {
                ({ camera, status, androidRecordAudioPermissionOptions }) => {
                  if (status !== 'READY') return <PendingView />

我知道有些事情没有做,但无法弄清楚,我需要有关此问题的帮助...此处的屏幕截图错误屏幕截图

4

1 回答 1

0

通过请求许可,我能够弄清楚。我用下面的代码解决了这个问题:

checkAndroidPermission = async () => {
    try {
      const permission = PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE;
      await PermissionsAndroid.request(permission);
      Promise.resolve();
    } catch (error) {
      Promise.reject(error);
    }
};

    takePicture = async () => {
        if (this.camera) {
          if (Platform.OS === 'android') {
            await this.checkAndroidPermission();
          }
            const options = { quality: 1 };
            const data = await this.camera.takePictureAsync(options);
            //save photo
            CameraRoll.save(data.uri, 'photo').then(onfulfilled => {
                ToastAndroid.show(onfulfilled, ToastAndroid.SHORT);
            }).catch(error => {
                ToastAndroid.show(`${error.message}`, ToastAndroid.SHORT);
            });
        }
    };

于 2020-06-30T13:27:05.680 回答