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

Created on 19 Sep 2019  路  11Comments  路  Source: bumptech/glide

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

Most helpful comment

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

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

All 11 comments

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

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

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.

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)

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

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


Thanks man, working perfect.

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

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

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
```

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.

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

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;
        }
    }
}

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)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Morteza-Rastgoo picture Morteza-Rastgoo  路  3Comments

ghost picture ghost  路  3Comments

MrFuFuFu picture MrFuFuFu  路  3Comments

kooeasy picture kooeasy  路  3Comments

r4m1n picture r4m1n  路  3Comments