【发布时间】:2020-01-01 17:26:29
【问题描述】:
在我发送图像的过程之后,我将其保存在内部存储中,并将 imageUri 路径保存到我的模型。
val localUriName = "${server}_${clientMessageId}_${filename}" context.openFileOutput(localUriName, Context.MODE_PRIVATE).use {
it.write(compactFile.toByteArray())
}
fileInformation.localUri = "${context.filesDir}${File.separator}$localUriName"
在调试代码时,我看到 localUri 的值类似于“data/user/0/files/filename.jpg”
在我的活动中,我想显示图像,所以我尝试使用 FileProvider 获取文件的 uri,但出现异常
val uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, File(it.localUri))
Failed to find configured root that contains /data/data/com.package.name/files/100_52_IMG-17f68c26802dc5306ac1c773be23e7f8-V.jpg
我的 file_provider_paths 如下
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path
name="files"
path="." />
<external-files-path
name="files"
path="." />
<external-path
name="files"
path="."/>
</paths>
那么为什么我将它保存在数据/用户中,但我从数据/数据中检索它??
【问题讨论】:
-
“那么为什么我将它保存在数据/用户中,但我从数据/数据中检索它??” -- 从您的应用程序的角度来看,它们是相同的位置。 “我的 file_provider_paths 如下”- 为
name使用唯一值。 -
您的意思是问题与我在路径 xml 中的 name="files" 相同?
标签: android kotlin android-fileprovider internal-storage