【发布时间】:2021-05-24 18:18:25
【问题描述】:
我正在使用 Glide 库将图像加载到 ImageView。
由于图像存储在缓存中,我正在尝试通过 Glide 访问它并获取它的 Uri 以通过Intent 发送以打开另一个应用程序以查看全屏图像。
我将图片加载到imageView的方式:
val url = GlideUrl(
BASE_URL + "/api/files/download/?id=${list[position].fileID}",
LazyHeaders.Builder()
.addHeader(
"token",
SessionManager.getInstance(context)
?.getSession()
?.token!!
)
.build())
Glide
.with(imageViewAttachment)
.load(url)
.apply(RequestOptions()
.fitCenter()
.format(DecodeFormat.PREFER_ARGB_8888)
.override(Target.SIZE_ORIGINAL)
)
.into(imageViewAttachment)
尝试通过Intent发送Uri的方式:
val file = Glide
.with(context)
.asFile()
.load(url)
.submit()
.get()
val uri = FileProvider
.getUriForFile(
context,
context.applicationContext.packageName + ".fileprovider",
file
)
val intent = Intent(Intent.ACTION_VIEW)
intent.setDataAndType(uri, "image/*")
context.startActivity(intent)
这是从缓存加载文件到 ImageView 时的日志:
2021-05-24 19:04:43.310 24974-24974/com.machadolemos.situations D/Glide: Finished loading BitmapDrawable from DATA_DISK_CACHE for http://qa2.machadolemos.com:60600/api/files/download/?id=1 with size [-2147483648x-2147483648] in 85.683021 ms
2021-05-24 19:04:43.801 24974-24974/com.machadolemos.situations D/Glide: Finished loading BitmapDrawable from DATA_DISK_CACHE for http://qa2.machadolemos.com:60600/api/files/download/?id=5 with size [-2147483648x-2147483648] in 561.9556769999999 ms
2021-05-24 19:04:45.983 24974-25079/com.machadolemos.situations D/Glide: Finished loading File from DATA_DISK_CACHE for http://qa2.machadolemos.com:60600/api/files/download/?id=5 with size [-2147483648x-2147483648] in 5.795208 ms
2021-05-24 19:04:48.545 24974-25043/com.machadolemos.situations I/Adreno: QUALCOMM build : 2df12b3, I07da2d9908
Build Date : 10/04/18
OpenGL ES Shader Compiler Version: EV031.25.03.01
Local Branch :
Remote Branch :
Remote Branch :
Reconstruct Branch :
2021-05-24 19:04:48.545 24974-25043/com.machadolemos.situations I/Adreno: Build Config : S L 6.0.7 AArch64
2021-05-24 19:04:48.548 24974-25043/com.machadolemos.situations D/vndksupport: Loading /vendor/lib64/hw/gralloc.msm8953.so from current namespace instead of sphal namespace.
2021-05-24 19:04:48.552 24974-25043/com.machadolemos.situations I/Adreno: PFP: 0x005ff087, ME: 0x005ff063
2021-05-24 19:04:48.554 24974-25043/com.machadolemos.situations I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2021-05-24 19:04:48.554 24974-25043/com.machadolemos.situations I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2021-05-24 19:04:48.555 24974-25043/com.machadolemos.situations I/OpenGLRenderer: Initialized EGL, version 1.4
2021-05-24 19:04:48.555 24974-25043/com.machadolemos.situations D/OpenGLRenderer: Swap behavior 2
The result of the Intent after selecting app to open the image is this toast saying Media not found
对这个问题有帮助吗?
【问题讨论】:
-
在调用 FileProvider 之前是否使用过 file.exists()?你看过它的绝对路径吗?
-
我没有。我会测试一下,让你知道。但我几乎可以肯定该文件存在。
-
file= /data/user/0/com.machadolemos.situations/cache/image_manager_disk_cache/ea98e9238eca3f23bc387c7943219e1d76ab97f2a13d783fed2564c287c6b31a.0
-
uri= content://com.machadolemos.situations.fileprovider/cache/image_manager_disk_cache/ea98e9238eca3f23bc387c7943219e1d76ab97f2a13d783fed2564c287c6b31a.0
-
刚刚调试了一下,文件和uri都存在
标签: android kotlin android-intent android-glide android-image