【问题标题】:Saving file to filesDir but goes to data/user将文件保存到 filesDir 但转到数据/用户
【发布时间】: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


【解决方案1】:

好吧,问题似乎在于我在 file_provider_paths.xml 中具有相同的“名称”值。我改变了它们,它工作正常!

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <files-path
        name="internal_files"
        path="." />

    <external-files-path
        name="external_path_files"
        path="." />

    <external-path
        name="external_files"
        path="."/>
</paths>

【讨论】:

    猜你喜欢
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    • 2020-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多