Android &引用;“未找到媒体”;尝试使用Intent.ACTION\u视图时

Android &引用;“未找到媒体”;尝试使用Intent.ACTION\u视图时,android,kotlin,android-intent,android-glide,android-image,Android,Kotlin,Android Intent,Android Glide,Android Image,我正在使用Glide库将图像加载到ImageView。 由于图像存储在缓存中,我试图通过Glide访问它,并通过Intent获取要发送的Uri,以打开另一个应用程序查看全屏图像 将图像加载到imageView的方式: val url=GlideUrl( BASE_URL+“/api/files/download/?id=${list[position].fileID}”, LazyHeaders.Builder() .addHeader( “代币”, SessionManager.getInst

我正在使用Glide库将图像加载到
ImageView
。 由于图像存储在缓存中,我试图通过Glide访问它,并通过
Intent
获取要发送的Uri,以打开另一个应用程序查看全屏图像

将图像加载到
imageView
的方式:

val url=GlideUrl(
BASE_URL+“/api/files/download/?id=${list[position].fileID}”,
LazyHeaders.Builder()
.addHeader(
“代币”,
SessionManager.getInstance(上下文)
?.getSession()
代币
)
.build())
滑翔
.带有(imageViewAttachment)
.load(url)
.apply(RequestOptions()
.fitCenter()
.format(DecodeFormat.preference_ARGB_8888)
.override(目标尺寸\原始尺寸)
)
.into(imageViewAttachment)
试图通过
Intent
发送Uri的方法:

val文件=滑动
.与(上下文)
.asFile()文件
.load(url)
.提交()
.get()
val uri=FileProvider
.getUriForFile(
上下文
context.applicationContext.packageName+“.fileprovider”,
文件
)
val intent=intent(intent.ACTION_视图)
intent.setDataAndType(uri,“image/*”)
上下文。起始触觉(意图)
这是从将文件从缓存加载到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


这个问题有什么帮助吗?

我未经测试的意见是,您正在尝试立即访问文件,而文件可能尚未加载,因此您应该在Glide调用中添加一个侦听器,并在onResourceReady回调下创建意图

Glide.with(this)
            .load(glideUrl)
            .apply(requestOptions)
            .into(object : SimpleTarget<File>(){
                override fun onResourceReady(resource: File?, transition: Transition<in File>?) {
                    //handle resource and create intent
                }
            })
Glide.with(这个)
.load(glideUrl)
.apply(请求选项)
.into(对象:SimpleTarget(){
覆盖onResourceReady(资源:文件?,转换:转换?){
//处理资源并创建意图
}
})

在调用文件提供商之前,您是否使用过file.exists()?你有没有看过它的绝对路径?我没有。我会测试一下,然后告诉你。但我几乎可以肯定该文件存在。file=/data/user/0/com.machadolemos.sitions/cache/image\u manager\u disk\u cache/ea98e9238eca3f23bc387c7943219e1d76ab97f2a13d783fed2564c287c6b31a.0uri=content://com.machadolemos.situations.fileprovider/cache/image_manager_disk_cache/ea98e9238eca3f23bc387c7943219e1d76ab97f2a13d783fed2564c287c6b31a.0Just 做调试失败,文件和uri已存在。尝试此操作失败。当使用不同的应用程序打开时,我确实注意到了一个新的警告应用程序无法打开此类型的文件“”。所以我查看了Android Studio中的设备管理器,并检查了文件的位置。缓存文件确实存在,但它们以.0结尾,所以我猜,因为扩展名不是.jpg或.png,所以无法识别。我检查了这个答案。解决方案是创建一个新文件.jpg,通过Intent使用。我唯一关心的是,每次用户单击该图像时,它都会创建一个新文件,因此最终会得到同一图像的多个副本。我的建议是不使用Glide下载文件,但通过改装或任何其他方法,将文件保存到缓存,单击后检查文件是否已存在,如果不存在,则下载,thaan显示给用户,请检查此链接关于重新安装