【问题标题】:FileProvider can't retrieve image from storage in AndroidFileProvider 无法从 Android 中的存储中检索图像
【发布时间】:2018-10-11 12:55:16
【问题描述】:

我正在尝试从应用程序的存储中检索图像。 我有一个在file:///data/user/0/com.myapp.android.debug/cache/cropped4227942271894219596.jpg 中存储图像的库。

我正在尝试通过执行以下操作来检索图像:

getUriForFile(context, context.applicationInfo.packageName + ".fileprovider", File(imageUri)) 但我得到的只是:

Failed to find configured root that contains /file:/data/user/0/com.myapp.android.debug/cache/cropped4227942271894219596.jpg

我的provider_paths.xml 是:

<paths> <files-path name="internal_files" path="/cache" /> </paths>

有人知道问题可能是什么吗? 提前致谢!

【问题讨论】:

    标签: android android-file android-fileprovider


    【解决方案1】:

    尝试在filepath.xml 中添加以下代码,因为缓存文件需要在cache-path 中提及

    <cache-path name="cache_files" path="."  />
    

    【讨论】:

    • 希望您使用File cacheFile = new File(context.getCacheDir(), "your_file.ext"); 创建文件并提供WRITE_EXTERNAL_STORAGE 权限
    • 好吧,我不创建,它是创建它的库;它被创建并且存在。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-23
    • 1970-01-01
    • 2019-07-31
    • 1970-01-01
    • 2012-06-30
    • 1970-01-01
    相关资源
    最近更新 更多