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

on Android 10 (Q) , Glide failed to load image from Image from local storage #3896

Closed
rahulpwar654 opened this issue Sep 19, 2019 · 17 comments
Closed

Comments

@rahulpwar654
Copy link

rahulpwar654 commented Sep 19, 2019

on Android 10 , Glide failed to load image from local storage.
I have tried gettting WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permission at runtime but still getting same error but works fine devices below Android 10.

I am Assuming its due to Scoped Storage in Android 10.
Scoped Storage
Testing on Essential Ph-1 with Android 10.

Glide: Load failed for file:///storage/emulated/0/Pictures/Screenshots/Screenshot_20190918-111135.png with size [306x306]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
    There were 3 causes:
    **java.io.FileNotFoundException(/storage/emulated/0/Pictures/Screenshots/Screenshot_20190918-111135.png: open failed: EACCES (Permission denied))**
    **java.io.FileNotFoundException(open failed: EACCES (Permission denied))**
    java.io.FileNotFoundException(open failed: EACCES (Permission denied))
     call GlideException#logRootCauses(String) for more detail
      Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, LOCAL
    There was 1 cause:
    java.io.FileNotFoundException(/storage/emulated/0/Pictures/Screenshots/Screenshot_20190918-111135.png: open failed: EACCES (Permission denied))
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
    There was 1 cause:
    java.io.FileNotFoundException(/storage/emulated/0/Pictures/Screenshots/Screenshot_20190918-111135.png: open failed: EACCES (Permission denied))
     call GlideException#logRootCauses(String) for more detail
          Cause (1 of 1): class java.io.FileNotFoundException: /storage/emulated/0/Pictures/Screenshots/Screenshot_20190918-111135.png: open failed: EACCES (Permission denied)
      Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class android.os.ParcelFileDescriptor, LOCAL
    There was 1 cause:
    java.io.FileNotFoundException(open failed: EACCES (Permission denied))
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
    There was 1 cause:
    java.io.FileNotFoundException(open failed: EACCES (Permission denied))
     call GlideException#logRootCauses(String) for more detail
          Cause (1 of 1): class java.io.FileNotFoundException: open failed: EACCES (Permission denied)
      Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class android.content.res.AssetFileDescriptor, LOCAL
    There was 1 cause:
    java.io.FileNotFoundException(open failed: EACCES (Permission denied))
     call GlideException#logRootCauses(String) for more detail
@rahulpwar654 rahulpwar654 changed the title on Android 10 , Glide failed to load image from Image from local storage on Android 10 (Q) , Glide failed to load image from Image from local storage Sep 19, 2019
@rahulpwar654
Copy link
Author

I have found workaround for above issue on below link
fix for above issue
add
android:requestLegacyExternalStorage="true"
inside your application tag ```

<application
android:name=".App"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true"
... >




@sjudd
Copy link
Collaborator

sjudd commented Sep 19, 2019

https://developer.android.com/training/data-storage/files/external-scoped

It's complicated unfortunately :/. The other option is to try to open images using MediaStore Uris rather than file paths.

@saeed-younus
Copy link

This is solve by passing Uri instead of string in load method of glide, just like this

              GlideApp.with(imageView.context)
                    .load(Uri.parse("file path in string"))
                    .into(imageView)

@sandeepmaaram
Copy link

sandeepmaaram commented Dec 3, 2019

I have found workaround for above issue on below link
fix for above issue
add
android:requestLegacyExternalStorage="true"
inside your application tag ```

<application
android:name=".App"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true"
... >


Thanks man, working perfect.

@Ekta-D
Copy link

Ekta-D commented Mar 8, 2020

Add android:usesCleartextTraffic="true" in Manifest will start working

@rahulpwar654
Copy link
Author

Add android:usesCleartextTraffic="true" in Manifest will start working

Sorry this won't work. This tag is used for allowing HTTP ( cleartext network traffic) endpoint in App.
you can read all this here
Allowing HTTP endpoints in android

@Dipongkar12
Copy link

Is there solution for this error```

W/Glide: Load failed for https://firebasestorage.googleapis.com/v0/b/mfree-9290a.appspot.com/o/uploads%2F1585227800859.null?alt=media&token=b8954c84-f1c7-4c9d-b94e-c76bece7b1c6 with size [120x120]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
java.net.SocketTimeoutException(SSL handshake timed out)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE
There was 1 cause:
java.net.SocketTimeoutException(SSL handshake timed out)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
There was 1 cause:
java.net.SocketTimeoutException(SSL handshake timed out)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class java.net.SocketTimeoutException: SSL handshake timed out
2020-03-30 11:33:28.880 13140-13140/com.example.mfree I/Glide: Root cause (1 of 1)
java.net.SocketTimeoutException: SSL handshake timed out

iamareebjamal pushed a commit to fossasia/phimpme-android that referenced this issue Apr 10, 2020
* IconicsContextWrapper is crashing

* fix `GROUP BY` query hack

* workaround fix for Android 10 Glide failed to load image

* see bumptech/glide#3896
@leephela
Copy link

leephela commented Jun 7, 2020

I seems to have finally found the real cause to this problem, this issue is not limited to just some few manufacturers but to all the android 10 devices on a whole. Be it you are targeting api 28 and below or 29, if you are on android 10, then chances are you will encounter this issues.

The real issues seems to be coming out from MediaMetadataRetriver class of the native android system that glide uses it to retrieved thumbnails/videoframes from media file. This MediaMetadataRetriver class of android is so unreliable , that once it got stuck somewhere in the process of retrieving, the whole other retrieval process got queued up and remain stuck forever there until it recovered again from that stuck, thus leading to a huge list of blank images.

The only viable solution is - write your own glide module to retrieve thumbnails for video, FFmpegMediaMetadataRetrieval seems to be a very good and reliable alternative to the native built in android ones.

@Roisfaozi
Copy link

i have error log like this

2020-08-12 18:19:30.825 23777-23777/com.kotlin.githubuser W/Glide: Load failed for https://avatars3.githubusercontent.com/u/121695?v=4 with size [200x200]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
2020-08-12 18:43:17.855 23777-23777/com.kotlin.githubuser D/ViewRootImpl[DetailActivity]: changeCanvasOpacity: opaque=false
2020-08-12 18:43:18.088 23777-23777/com.kotlin.githubuser D/ViewRootImpl[DetailActivity]: changeCanvasOpacity: opaque=true

@xinooo
Copy link

xinooo commented Sep 10, 2020

use SAF

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
            case 0:
                Glide.with(MainActivity.this)
                        .load(data.getData())
                        .into(iv);
                break;
            default:
                break;
        }
    }
}

@LiuJQ
Copy link

LiuJQ commented Nov 19, 2020

This is solve by passing Uri instead of string in load method of glide, just like this

              GlideApp.with(imageView.context)
                    .load(Uri.parse("file path in string"))
                    .into(imageView)

Unfortunately, you can't factory Uri like that instead of this :

val uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id)

@dfabreguette
Copy link

For me, problem was that Uri parse method was failing as it missed "file://" prefix :

Uri.parse("/storage...")

This is the right way to do it :

Uri.parse("file://storage...")

@skyboardsoftware
Copy link

skyboardsoftware commented Mar 11, 2022

he whole other retrieval process got queued up and remain stuck forever there until it recovered again from that stuck, thus leading to a huge list of blank images.

I too had blank images, during my camera process the intent did not get a proper uri in my situation. I just upgraded to Android 11 and discovered all these new issues. So I used a file provider for the answer and my 0 byte files became filled with camera data, and of course in the file provider's new location.

contentUri = FileProvider.getUriForFile(MainActivity.this, BuildConfig.APPLICATION_ID + ".provider", file);

I was stuck for a little bit...

@pramodkumarp6
Copy link

I have same problem

@01masterdisk
Copy link

I have found workaround for above issue on below link fix for above issue add android:requestLegacyExternalStorage="true" inside your application tag ```

<application android:name=".App" android:allowBackup="false" android:icon="@mipmap/ic_launcher" android:requestLegacyExternalStorage="true" ... >


this a temporary solution,
not work now.

@asimkaka-coder
Copy link

asimkaka-coder commented Sep 21, 2022

Found this on stackoverflow, and it worked for me by directly passing Uri

You have to pass the related uri, not the path,

Glide.with(context).load(model.photoUri).into(image)

By this you don't need to add

android:requestLegacyExternalStorage="true"

in your Manifest file.

@wiryadev
Copy link

this issue still exist?

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