siralam / BSImagePicker

An image picker that extends BottomSheetDialogFragment. Camera and gallery all in one dialog. Single or Multi Selection.
202 stars 62 forks source link

Library not working on Android Q (API 29) #33

Open akrezic1 opened 5 years ago

akrezic1 commented 5 years ago

There is an issue with permissions because of Scoped Storage and it's giving this stacktrace:

java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/IMG_20190606_105527.jpg: open failed: EACCES (Permission denied) at libcore.io.IoBridge.open(IoBridge.java:496) at java.io.RandomAccessFile.<init>(RandomAccessFile.java:289) at com.bumptech.glide.util.ByteBufferUtil.fromFile(ByteBufferUtil.java:43) at com.bumptech.glide.load.model.ByteBufferFileLoader$ByteBufferFetcher.loadData(ByteBufferFileLoader.java:65) at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62) at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302) at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:272) at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:233) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:919) at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446) Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied) at libcore.io.Linux.open(Native Method) at libcore.io.ForwardingOs.open(ForwardingOs.java:167) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252) at libcore.io.ForwardingOs.open(ForwardingOs.java:167) at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7218) at libcore.io.IoBridge.open(IoBridge.java:482) at java.io.RandomAccessFile.<init>(RandomAccessFile.java:289)  at com.bumptech.glide.util.ByteBufferUtil.fromFile(ByteBufferUtil.java:43)  at com.bumptech.glide.load.model.ByteBufferFileLoader$ByteBufferFetcher.loadData(ByteBufferFileLoader.java:65)  at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)  at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302)  at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:272)  at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:233)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)  at java.lang.Thread.run(Thread.java:919)  at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446) 

Tested on Android Studio 3.5 Beta 3 with Pixel 3 API 29 emulator. To test it you need to set compileSdkVersion and targetSdkVersion to 29.

siralam commented 5 years ago

Guess for now you would have to lower the target SDK version, but I will make it in the future version. Thanks for the report!

barnhill commented 4 years ago

Ran into this myself. You can get around this by feeding glide the Uri instead of the path

sjd753 commented 4 years ago

Having the same issue here. when are you going to fix it for Q api 29? what else can be done to get around it?

Ran into this myself. You can get around this by feeding glide the Uri instead of the path

how to do this?

barnhill commented 4 years ago

It's one of the overloaded methods ... Can't remember off the top of my head. Make sure you use the latest glide too.

yesidlazaro commented 4 years ago

hi, any progress here?

engr-erum commented 4 years ago

Hi , Any progress for Android Q ?

siralam commented 4 years ago

Sorry guys I have been quite busy recently, but I will try to get this done this month. If not this month may be in Februaray then.

bemrePG commented 4 years ago

Ran into this myself. You can get around this by feeding glide the Uri instead of the path

Hi, just tried it with passing the uri. Still doesn't work. Any workaround for the mean time?

siralam commented 4 years ago

Hey guys, simply by adding android:requestLegacyExternalStorage="true" to your <application> tag in AndroidManifest should fix the problem for now. Anyone tried?

bemrePG commented 4 years ago

Hi, works great! Thank you very much.

siralam commented 4 years ago

Guys, yesterday I spent quite some time looking into this and I still cannot find a way to do it perfectly in all versions. I think there are still quite a lack of resources about this topic in the community, and even the Android documentation has not updated yet 🤷‍♂

So for now I decided to just leave it as the original way and just use android:requestLegacyExternalStorage="true".

Greger34 commented 3 years ago

Seems to work fine with glide.

    @Override
    public void loadImage(Uri imageUri, ImageView ivImage)
    {
        Glide.with(this).load(imageUri).into(ivImage);
    }

but you need to do some magic in public void onSingleImageSelected(Uri uri, String tag) to be able to do something with the image afterwards. Mainly copying the image to local cache using file descriptor. You can read more about it here: https://medium.com/@sriramaripirala/android-10-open-failed-eacces-permission-denied-da8b630a89df

After doing those things it works as intended for me without needing the android:requestLegacyExternalStorage="true"