react-native-image-picker icon indicating copy to clipboard operation
react-native-image-picker copied to clipboard

[Android] Permissions were not granted

Open beshur opened this issue 8 years ago • 8 comments

Description

On my Nexus 5x (Android 6) emulator I click Allow for permissions request, but console always says 'ImagePicker Error: ', 'Permissions weren't granted' build.gradle has targetSdkVersion 22, compileSdkVersion 23.

How to repeat issue and example

Trying to launch the image picker from example - clicking Take Photo or Select From Gallery.

Solution

Should work.

Additional Information

  • React Native version: 0.55.2
  • Platform: Android
  • Development Operating System: OS X
  • Dev tools: Android Studio 2.3.3, Android SDK up to 27

Thanks!

beshur avatar May 07 '18 21:05 beshur

Also tried to lower the API version and build the app for my physical device with Android 5.0.1.

But it just crashes when triggering Take a Photo/Choose from library.

05-08 23:06:31.228 25746-25790/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
                                                   Process: com.xpyry, PID: 25746
                                                   java.lang.NoSuchMethodError: No virtual method requestPermissions([Ljava/lang/String;I)V in class Landroid/app/Activity; or its super classes (declaration of 'android.app.Activity' appears in /system/framework/framework.jar)
                                                       at com.facebook.react.ReactActivityDelegate.requestPermissions

beshur avatar May 08 '18 20:05 beshur

Wee! Fixed in emulator (Android 6) by adding permissions in the correct AndroidManifest.xml (./android/app/src/main/AndroidManifest.xml, not the one somewhere in the generated app directory)

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

beshur avatar May 08 '18 21:05 beshur

Hi @beshur am still having this issue, it says

Permissions weren't granted

nwaughachukwuma avatar Oct 27 '18 04:10 nwaughachukwuma

Same problem on React-Native >= 0.55.

foo4foo avatar Nov 20 '18 21:11 foo4foo

His solution works for me, but i'm very newe in React Native, in another project I had to add a provider in my AndroidManifest.xml and then, only then it works for me, maybe can help you.

      <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:grantUriPermissions="true"
            android:exported="false">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
      </provider>

And create this filepaths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="files"  path="/" />
</paths>

jako-hub-old avatar May 16 '19 03:05 jako-hub-old

I had to add tools:node="replace" to <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace"/>

because one of my packages already asked for WRITE_EXTERNAL_STORAGE permission with attribute maxAndroidSdk=18, so I had to override it.

korzonkiee avatar Jul 22 '19 15:07 korzonkiee

The prefix "tools" for attribute "tools:node" associated with an element type "uses-permission" is not bound.

Anujmoglix avatar May 10 '20 19:05 Anujmoglix

The prefix "tools" for attribute "tools:node" associated with an element type "uses-permission" is not bound.

you have to bind the tools attribute to your manifest element: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="[YOUR APP NAME]" xmlns:tools="http://schemas.android.com/tools" >

blake-spire avatar Sep 29 '20 19:09 blake-spire