[Android] Permissions were not granted
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!
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
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" />
Hi @beshur am still having this issue, it says
Permissions weren't granted
Same problem on React-Native >= 0.55.
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>
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.
The prefix "tools" for attribute "tools:node" associated with an element type "uses-permission" is not bound.
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"
>