Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permissions related error in Android API level 30 #776

Open
rajeev-xyz opened this issue Aug 9, 2020 · 12 comments
Open

Permissions related error in Android API level 30 #776

rajeev-xyz opened this issue Aug 9, 2020 · 12 comments

Comments

@rajeev-xyz
Copy link

I know this is working great till API Level 29 but in latest API level 30 - I see error after taking picture using camera in my app.

Error is "Cancelling, required permissions are not granted".

Screenshot attaching.
Screenshot 2020-08-09 at 3 49 27 PM

@karelkryda
Copy link

Same problem on Android 11. Pick from gallery working properly, but camera shows permission denied.

(Working on Android 10)

@Canato
Copy link

Canato commented Sep 7, 2020

Same =/

@leducthuy
Copy link

Oh, Which device did you get this error. I didn't get this in my device (Pixel 2 XL - Android 11)

@rajeev-xyz
Copy link
Author

I get this error on Pixal 3a, API 30 when I changed my target version in Build file to 30.

@karelkryda
Copy link

Target version 30...Pixel 3X (I think) API 30 (Android R)

@leducthuy
Copy link

My app has targetSdkVersion = 30 too. But I checked the camera permission before using

@Canato
Copy link

Canato commented Sep 10, 2020

So, the solution is not related to this library, since this library will take the picture after we already have it saved in a URI.

The solution for us was change the URI from external to the authority(fileProvider) URI

val photoURI: Uri = FileProvider.getUriForFile(this, "com.example.android.fileprovider", it)

based on https://developer.android.com/training/camera/photobasics#kotlin

Hope this help more people

This change was based on the new Android 11 storage permissions https://developer.android.com/about/versions/11/privacy/storage
now we should not use WRITE/READ permissions but we can use a directly app storage

@GulmirzaNorboyev
Copy link

So, the solution is not related to this library, since this library will take the picture after we already have it saved in a URI.

The solution for us was change the URI from external to the authority(fileProvider) URI

val photoURI: Uri = FileProvider.getUriForFile(this, "com.example.android.fileprovider", it)

based on https://developer.android.com/training/camera/photobasics#kotlin

Hope this help more people

This change was based on the new Android 11 storage permissions https://developer.android.com/about/versions/11/privacy/storage
now we should not use WRITE/READ permissions but we can use a directly app storage

Hello @Canato bro! My problem is that nothing is visible when I take a picture from the camera ... So how do you recommend how to put your recommended solution into the library! If you have changed this library to suit you (fork), please share your codes with me too !!!

@Canato
Copy link

Canato commented Sep 17, 2020

@GulmirzaNorboyev Hey =D. This code is not inside the project, I do this before call the crop library

So I open the camera before use CropImage library.

My problem is that nothing is visible when I take a picture from the camera

Try to open the camera with the google code, after this you can this library to Crop the image

@iori57
Copy link

iori57 commented Oct 30, 2020

I can reproduce it in my physical Google Pixel 4 device, and also in Android emulator of Pixel 3a, on API 30.

When debugging, I found that the problem does not lie in the permission, but it is because inside the function getCaptureImageOutputUri() in CropImage.java,
context.getExternalCacheDir(); is returning null

it is throwing that permission error because there is a null check on the same if statement... so if the url is null it will throw that permission error on the first try, and subsequent try will just crash the app if the permission already granted.

I think this library need to apply a fix suggested by @Canato to address this issue

@Canato
Copy link

Canato commented Nov 16, 2020

Looking into the code, we would need to change all Uri.fromFile(file) cases to FileProvider.getUriForFile(context, AUTHORITY, file)

BitmapUtils
CropImageActivity
CropImage

But this is just the first bit, still need more work on it. Get the authority will be already something trick to do.

This would fix:

@Canato
Copy link

Canato commented Nov 27, 2020

Hey!

I start a new project to handover this library
https://github.com/CanHub/Android-Image-Cropper

The ideia is that we keep improving because this project don’t have updates since 2018
Hope I can count with your help.

Open to contribute, next pieces of work will be Android 11 permissions, refactor into Kotlin and ActivityContract

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants