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

Android permissions error: Required permission missing

Open kjossendal opened this issue 4 years ago • 13 comments

Version

Tell us which versions you are using:

  • react-native-image-crop-picker v0.35.0
  • react-native v0.63.2
  • gradle stuff buildToolsVersion = "29.0.3" ext.kotlin_version = '1.3.21' minSdkVersion = 19 compileSdkVersion = 29 targetSdkVersion = 29

Platform

  • Android only (iOS works correctly)

Expected behaviour

I should be able to open camera and/or cropper

Actual behaviour

Continually getting ambiguous error 'Error: Required permission missing' when attempting to call any ImagePicker methods

Steps to reproduce

  1. Follow android install steps as of Sept 29th 2020

  2. Attempt to call ImagePicker.openCamera() or ImagePicker.openCropper()

Attachments

Receiving this error.

Error: Required permission missing
    at Object.promiseMethodWrapper [as openCamera] (NativeModules.js:103)
    at CollagePhotoFrame._this.cropPhoto (CollagePhotoFrame.js:18)
    at onPress (CollagePhotoFrame.js:81)
    at Pressability._performTransitionSideEffects (Pressability.js:697)
    at Pressability._receiveSignal (Pressability.js:634)
    at onResponderRelease (Pressability.js:530)
    at Object.invokeGuardedCallbackImpl (ReactNativeRenderer-dev.js:265)
    at invokeGuardedCallback (ReactNativeRenderer-dev.js:476)
    at invokeGuardedCallbackAndCatchFirstError (ReactNativeRenderer-dev.js:500)
    at executeDispatch (ReactNativeRenderer-dev.js:597)

I have the permissions set in AndroidManifest for CAMERA, WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE I've tried explicitly asking for permissions like so.

componentDidMount() {
    PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE)
    PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE)
    PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA)
  }

I've noticed WRITE_EXTERNAL_STORAGE always returns 'never_ask_again' no matter what the user does. I've tried rolling back to '0.32.2' to no avail. I've tried setting sdk target and compile version to 27 but that breaks other things in the app so I couldn't test. I've also set android:requestLegacyExternalStorage="true" in AndroidManifest to no avail. I've tried running on a simulator running android 10, a simulator running android 9, a OnePlus 7 running android 10.2, and a OnePlus 5 running android 10.

kjossendal avatar Sep 29 '20 17:09 kjossendal

I've found out that if I go into the source to PickerModule.java and disable the permission check, the cropper appears to work correctly. My java skills are pretty much non existent so I can't say where the problem stems from. PickerModule.java

@ReactMethod
    public void openCropper(final ReadableMap options, final Promise promise) {
        final Activity activity = getCurrentActivity();

        if (activity == null) {
            promise.reject(E_ACTIVITY_DOES_NOT_EXIST, "Activity doesn't exist");
            return;
        }

        setConfiguration(options);
        resultCollector.setup(promise, false);

        final Uri uri = Uri.parse(options.getString("path"));
        // permissionsCheck(activity, promise, Collections.singletonList(Manifest.permission.WRITE_EXTERNAL_STORAGE), new Callable<Void>() {
            // @Override
            // public Void call() {
                startCropping(activity, uri);
                // return null;
            // }
        // });
    }

kjossendal avatar Sep 29 '20 18:09 kjossendal

Android changed to only asking permissions the moment you need them. So you can't pre-ask a permission anymore at app start for example. So where it used to just ask for that permission, even though it did not need it, now the Android system suppresses the permissions request, and the check still throws. As long as you are supporting a minSdk version of 19, this appears to be safely removable.

kjossendal avatar Sep 29 '20 19:09 kjossendal

WRITE_EXTERNAL_STORAGE seems like it needs a wee bit more permission than normal.

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

seems to work for me

initialsaet avatar Sep 30 '20 23:09 initialsaet

WRITE_EXTERNAL_STORAGE seems like it needs a wee bit more permission than normal.

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

seems to work for me

you just saved my day @initialsaet, not gonna lie! thanks!

artieeg avatar Oct 02 '20 10:10 artieeg

@initialsaet Thank you so much! What a life saver!

cameronadams777 avatar Oct 06 '20 05:10 cameronadams777

I think this should be highlighted in the README. @initialsaet 's solution is working.

saniagh avatar Dec 12 '20 22:12 saniagh

WRITE_EXTERNAL_STORAGE似乎需要比通常更多的权限。

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

似乎为我工作

WRITE_EXTERNAL_STORAGE seems like it needs a wee bit more permission than normal.

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

seems to work for me

tools:node="replace" I can't compile it and I have to delete it

yfs-2000 avatar Mar 03 '21 02:03 yfs-2000

My issue was that I wasn't being able to use the crop-picker inside the emulator, Pixel XL API 13. After adding a log entry on PickerModule::permissionsCheck I was able to see the missing permission was READ_MEDIA_IMAGES.

Log.d("picker", "Missing Permissions " + missingPermissions);
01-14 21:57:09.254 19135 19200 D picker  : Missing Permissions [android.permission.READ_MEDIA_IMAGES]

Adding the permission to AndroidManifest fixed the problem. Now I get a prompt to allow access and it the crop picker works after granting it.

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

sliechti avatar Jan 15 '23 03:01 sliechti

My issue was that I wasn't being able to use the crop-picker inside the emulator, Pixel XL API 13. After adding a log entry on PickerModule::permissionsCheck I was able to see the missing permission was READ_MEDIA_IMAGES.

Log.d("picker", "Missing Permissions " + missingPermissions);
01-14 21:57:09.254 19135 19200 D picker  : Missing Permissions [android.permission.READ_MEDIA_IMAGES]

Adding the permission to AndroidManifest fixed the problem. Now I get a prompt to allow access and it the crop picker works after granting it.

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

This worked for me. I'm using api33, and after this, my image-crop-picker package is working fine.

AvinashKumar69 avatar May 16 '23 19:05 AvinashKumar69

Step 1: Install package react native permissions

Step 2: Add the below code in the AndroidManifest.xml file:

Step 3: Add the line inside AndroidManifest.xml and add in the application section:

android:requestLegacyExternalStorage="true"

Step 4: Add inside index.js file:

PERMISSIONS.ANDROID.CAMERA;

Usama-Saud avatar Jun 07 '23 11:06 Usama-Saud

I had some similar problem. I was using a resizable emulator device on Android Studio w/ API 33. Tbh though, I don't think that matters because I deleted my react-native-image-crop-picker dependency and reinstalled it--that fixed it.

BearGotGit avatar Aug 09 '23 17:08 BearGotGit

You're a GOD my man!!! Saved my life xD

henrryzuko avatar Sep 20 '23 18:09 henrryzuko

My issue was that I wasn't being able to use the crop-picker inside the emulator, Pixel XL API 13. After adding a log entry on PickerModule::permissionsCheck I was able to see the missing permission was READ_MEDIA_IMAGES.

Log.d("picker", "Missing Permissions " + missingPermissions);
01-14 21:57:09.254 19135 19200 D picker  : Missing Permissions [android.permission.READ_MEDIA_IMAGES]

Adding the permission to AndroidManifest fixed the problem. Now I get a prompt to allow access and it the crop picker works after granting it.

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

Is there a way I can add this permission using Expo?

hurshore avatar Oct 11 '23 10:10 hurshore