Fresco: targetSdk 29 (scoped storage) support?

Created on 10 Jan 2020  ·  14Comments  ·  Source: facebook/fresco

Description

Fresco failed to load images from EXTERNAL_CONTENT_URI e.g. content://media/external/images/media/8039, FileNotFoundException was seen from the logs

Reproduction

Loading images with EXTERNAL_CONTENT_URI content://media/external/images/media/8039

Solution

I found that inside com.facebook.imagepipeline.producers.LocalContentUriFetchProducer, given the above content uri, it will fall to the call getCameraImage and which in turn getting the absolute file path of the image. However, due to scoped storage in targetSdk 29, that wouldn't be allowed. Probably getting input stream like

ParcelFileDescriptor pfd = mContentResolver.openFileDescriptor(contentUri, "r");
FileInputStream fis = FileInputStream(pfd.getFileDescriptor());

Additional Information

  • Fresco version: 2.0.0
  • Platform version: Android 10
enhancement good first issue help wanted

Most helpful comment

@esafirm I've made this PR to show where I got to, if you could test that it works for you that would be great

All 14 comments

Has it fixed by v2.1.0 ? Anybody knows ?

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "bug" or "enhancement" and I will leave it open. Thank you for your contributions.

<manifest >
  <application 
        android:requestLegacyExternalStorage="true"
        tools:targetApi="q">
  </application>
</manifest>

use this solution as a temporary one

I think this is also the reason why video thumbs are not loaded on Android Q. See https://github.com/facebook/fresco/issues/2390

I’m seeing something similar. The content URI of a photo is being converted to a file URI which cannot be accessed in Android10 (targetSDK29)

Loading URI : “content://media/external/images/media/34”

gives error
{“error": "/storage/emulated/0/Download/portrait5.jpg: open failed: EACCES (Permission denied)"}

I'll take a look at fixing this

Hi @paulmasters do you still working on the fix? I would be happy to create one if you haven't

After checking the issue, i think this already being handled.
You have to request READ_EXTERNAL_STORAGE permission first though.
cc: @oprisnik

Ha @esafirm,
I started looking at it, but got diverted to a higher priority, sorry!
I think a fix requiring READ_EXTERNAL_STORAGE must be a temporary one since any direct access of file URLs will stop working, as I understand it.

My initial investigation suggested that removing the code here will fix the problem.
https://github.com/facebook/fresco/blob/master/imagepipeline/src/main/java/com/facebook/imagepipeline/producers/LocalContentUriFetchProducer.java#L71-L76
That code tests for external storage URIs ( not really camera URI),
then tries to make file URLs, which will not work in the future.

If we remove this and simply let the next line use the contentURL directly to open a stream that should work fine, but I did not get time to make a nice test case.

@esafirm I've made this PR to show where I got to, if you could test that it works for you that would be great

I'm still experiencing this problem.
Has it fixed ? In which version did this work? Does anyone know?

It is now October 2020

Since Android 11 become official, and it allow direct file access of Media Files again.

It is safe to say we could just simply use android:requestLegacyExternalStorage="true" when targetApi=29.

And when targetApi=30, even though the Android 11 force you to use Scoped Storage, Fresco could still use its old way to successfully display the image.

Loading the same image uri with Native ImageView, using Glide or Coil works, but not Fresco's SimpleDraweeView.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

satyarths picture satyarths  ·  3Comments

stevenmtang picture stevenmtang  ·  3Comments

eldk picture eldk  ·  3Comments

ykostova picture ykostova  ·  3Comments

rafaelekol picture rafaelekol  ·  4Comments