Error: Permissions not granted… react-native-image-picker

随声附和 提交于 2019-12-06 05:11:37

问题


I am trying to upload an image from internal memory in our client app, using

react-native-image-picker@^0.26.4

And after executing the following sample snippet i got the response in an unexpected way.

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
    })
  }

RESPONSE

  • Response = {error: "Permissions weren't granted"} error: "Permissions weren't granted"proto: Object D:\my_app\index.js:124 ImagePicker Error: Permissions weren't granted

  • Sometimes On Allow button press app unexpectedly crashes.

Additional Information

  • React Native version: ~0.46.1
  • React: 16.0.0-alpha.12
  • Platform: [Android 5.1 and above]
  • Development Operating System: [Windows 7 Professional]
  • Dev tools: [ Android Studio version 2.3.2, Android SDK 23]

回答1:


Add this code in your AndroidManifest.xml:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Edited this after suggestions by Jaffar Raza and szskdgi



来源:https://stackoverflow.com/questions/45711011/error-permissions-not-granted-react-native-image-picker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!