错误:未授予权限... react-native-image-picker

Pav*_*ddy 4 android gradle react-native android-studio-2.3

我正在尝试使用以下方式从客户端应用程序的内部存储器中上传图像

react-native-image-picker@^0.26.4

在执行以下示例代码片段后,我以意外的方式得到了响应。

ImagePicker.showImagePicker(options, response => {
  console.log("Response = ", response)

  if (response.didCancel) {
    console.log("User cancelled image picker")
  } else if (response.error) {
    console.log("ImagePicker Error: ", response.error)
  } else if (response.customButton) {
    console.log("User tapped custom button: ", response.customButton)
  } else {
    const source = { uri: response.uri }
    // RNGRP.getRealPathFromURI(response.uri).then(filePath => {
    //   uploadImageToS3(filePath, "dinesh")
    //   console.log(filePath)
    // })

    // You can also display  the image using data:
    // let source = { uri: 'data:image/jpeg;base64,' + response.data };

    this.setState({
      avatarSource: source
    })
  }
Run Code Online (Sandbox Code Playgroud)

响应

  • 响应= {错误:“未授予权限”}错误:“未授予权限” 原型:对象D:\ my_app \ index.js:124 ImagePicker错误:未授予权限

  • 有时,按“允许”按钮时,应用程序意外崩溃。

附加信息

  • React Native版本:〜0.46.1
  • 反应:16.0.0-alpha.12
  • 平台:[Android 5.1及更高版本]
  • 开发操作系统:[Windows 7 Professional]
  • 开发人员工具:[Android Studio版本2.3.2,Android SDK 23]

Zaf*_*nov 14

将此代码添加到您的AndroidManifest.xml

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Run Code Online (Sandbox Code Playgroud)

根据Jaffar Raza和szskdgi的建议进行编辑

  • &lt;uses-permission android:name =“ android.permission.WRITE_INTERNAL_STORAGE” /&gt;应该替换为&lt;uses-permission android:name =“ android.permission.WRITE_EXTERNAL_STORAGE” /&gt; (4认同)