diff --git a/library/src/main/java/com/bumptech/glide/load/data/mediastore/MediaStoreUtil.java b/library/src/main/java/com/bumptech/glide/load/data/mediastore/MediaStoreUtil.java index bd00853e12..46951a91e7 100644 --- a/library/src/main/java/com/bumptech/glide/load/data/mediastore/MediaStoreUtil.java +++ b/library/src/main/java/com/bumptech/glide/load/data/mediastore/MediaStoreUtil.java @@ -20,6 +20,12 @@ public static boolean isMediaStoreUri(Uri uri) { && MediaStore.AUTHORITY.equals(uri.getAuthority()); } + // Android picker uris contain a "picker" segment: + // https://android.googlesource.com/platform/packages/providers/MediaProvider/+/refs/heads/master/src/com/android/providers/media/PickerUriResolver.java#58 + public static boolean isAndroidPickerUri(Uri uri) { + return isMediaStoreUri(uri) && uri.getPathSegments().contains("picker"); + } + private static boolean isVideoUri(Uri uri) { return uri.getPathSegments().contains("video"); } diff --git a/library/src/main/java/com/bumptech/glide/load/model/stream/QMediaStoreUriLoader.java b/library/src/main/java/com/bumptech/glide/load/model/stream/QMediaStoreUriLoader.java index b19d655e3e..0ad102c8aa 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/stream/QMediaStoreUriLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/stream/QMediaStoreUriLoader.java @@ -156,6 +156,11 @@ private LoadData buildDelegateData() throws FileNotFoundException { if (Environment.isExternalStorageLegacy()) { return fileDelegate.buildLoadData(queryForFilePath(uri), width, height, options); } else { + // Android Picker uris have MediaStore authority and does not accept requireOriginal. + if (MediaStoreUtil.isAndroidPickerUri(uri)) { + return uriDelegate.buildLoadData(uri, width, height, options); + } + Uri toLoad = isAccessMediaLocationGranted() ? MediaStore.setRequireOriginal(uri) : uri; return uriDelegate.buildLoadData(toLoad, width, height, options); } diff --git a/library/test/src/test/java/com/bumptech/glide/load/data/mediastore/MediaStoreUtilTest.java b/library/test/src/test/java/com/bumptech/glide/load/data/mediastore/MediaStoreUtilTest.java new file mode 100644 index 0000000000..6c84f79ac6 --- /dev/null +++ b/library/test/src/test/java/com/bumptech/glide/load/data/mediastore/MediaStoreUtilTest.java @@ -0,0 +1,30 @@ +package com.bumptech.glide.load.data.mediastore; + +import static com.google.common.truth.Truth.assertThat; + +import android.net.Uri; +import android.provider.MediaStore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +@RunWith(RobolectricTestRunner.class) +@Config(sdk = 18) +public class MediaStoreUtilTest { + + @Test + public void isAndroidPickerUri_notAndroidPickerUri_returnsFalse() { + Uri mediaStoreUri = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, "123"); + + assertThat(MediaStoreUtil.isAndroidPickerUri(mediaStoreUri)).isFalse(); + } + + @Test + public void isAndroidPickerUri_identifiesAndroidPickerUri_returnsTrue() { + Uri androidPickerUri = + Uri.parse("content://media/picker/0/com.android.providers.media.photopicker/media/123"); + + assertThat(MediaStoreUtil.isAndroidPickerUri(androidPickerUri)).isTrue(); + } +}