bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.67k stars 6.12k forks source link

SecurityException while loading image uri from photo picker #5154

Open lipenny000 opened 1 year ago

lipenny000 commented 1 year ago

Glide Version: 4.15.1

Integration libraries: No

Device/Android Version: The issue is not specific to particular devices

Issue details / Repro steps / Use case background: We are trying to use Glide to load images selected from photo picker but got the error below: Load failed for [content://media/picker/0/com.android.providers.media.photopicker/media/1000000734] with dimensions [1440x2471] class com.bumptech.glide.load.engine.GlideException: Failed to load resource There was 1 root cause: java.lang.SecurityException(Calling uid ( 10118 ) does not have permission to access picker uri: content://media/picker/0/com.android.providers.media.photopicker/media/1000000734?requireOriginal=1)

However, we are able to access the image if we use MediaStore's getBitmap method with ContentResolver.

Glide load line / GlideModule (if any) / list Adapter code (if any):

Glide.with(context)
          .load(imageUriFromPhotoPicker)
          .into(findViewById(R.id.image_preview))
nangongkuo commented 1 year ago

我也遇到了相同的问题,报错如下: Request threw uncaught throwable java.lang.SecurityException: Calling uid ( 10770 ) does not have permission to access picker uri: content://media/picker/0/com.android.providers.media.photopicker/media/1000001670 at android.os.Parcel.createExceptionOrNull(Parcel.java:3011) at android.os.Parcel.createException(Parcel.java:2995) at android.os.Parcel.readException(Parcel.java:2978) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190) at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:153) at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:780) at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2027) at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1842) at android.content.ContentResolver.openInputStream(ContentResolver.java:1518) at com.bumptech.glide.load.data.StreamLocalUriFetcher.loadResourceFromUri(StreamLocalUriFetcher.java:74) at com.bumptech.glide.load.data.StreamLocalUriFetcher.loadResource(StreamLocalUriFetcher.java:50) at com.bumptech.glide.load.data.StreamLocalUriFetcher.loadResource(StreamLocalUriFetcher.java:13) at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:44) at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100) at com.bumptech.glide.load.model.stream.QMediaStoreUriLoader$QMediaStoreUriFetcher.loadData(QMediaStoreUriLoader.java:141) at com.bumptech.glide.load.engine.SourceGenerator.startNextLoad(SourceGenerator.java:95) at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:88) at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:311) at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:280) at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:235) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637) at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:424) at java.lang.Thread.run(Thread.java:1012) at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultPriorityThreadFactory$1.run(GlideExecutor.java:383)

我是想获取视频的第2秒作为封面,代码如下: Glide.with(context) .load(Uri.parse(item.pathUri)) .frame(2000000L) // 2秒 = 2,000,000微秒 .apply(RequestOptions().placeholder(drawable.img_def_grey_item)) .diskCacheStrategy(DiskCacheStrategy.ALL) // 缓存所有版本的图像 .into(imageView)

但是我获取默认的第0秒作为封面却没有问题,代码如下: Glide.with(imageView.context) .load(Uri.parse(item.pathUri)) .apply(RequestOptions().placeholder(drawable.img_def_grey_item)) .into(imageView)

我的手机系统是android 13, 并且我已经获取了READ_MEDIA_IMAGES,READ_MEDIA_VIDEO,READ_MEDIA_AUDIO权限,请问这是为什么?

Glide的版本是4.15.1