BSImagePicker icon indicating copy to clipboard operation
BSImagePicker copied to clipboard

Library not working on Android Q (API 29)

Open akrezic1 opened this issue 5 years ago • 12 comments

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.

akrezic1 avatar Jun 06 '19 11:06 akrezic1

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!

siralam avatar Jun 07 '19 06:06 siralam

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

barnhill avatar Aug 30 '19 00:08 barnhill

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?

sjd753 avatar Oct 03 '19 12:10 sjd753

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

barnhill avatar Oct 03 '19 12:10 barnhill

hi, any progress here?

yesidlazaro avatar Dec 06 '19 16:12 yesidlazaro

Hi , Any progress for Android Q ?

engr-erum avatar Jan 10 '20 08:01 engr-erum

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.

siralam avatar Jan 16 '20 02:01 siralam

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?

bemrePG avatar Jan 16 '20 08:01 bemrePG

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

siralam avatar Jan 17 '20 09:01 siralam

Hi, works great! Thank you very much.

bemrePG avatar Jan 17 '20 09:01 bemrePG

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".

siralam avatar Jan 21 '20 09:01 siralam

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"

Greger34 avatar Feb 17 '21 11:02 Greger34