gpt4 book ai didi

android - 如何为具有动态应用程序 ID 的应用程序指定路径外部路径

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:22:36 25 4
gpt4 key购买 nike

我在我的应用程序中使用 FileProvider,当我从应用程序中拍摄照片时,它会存储在那里。我的应用程序也有不同的应用程序 ID 用于调试和发布版本

  • com.rkmax.myapp
  • com.rkmax.myapp.debug

我已经这样定义了我的文件提供者

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="@string/authority_file_provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>

@string/authority_file_provider 的值会变成:

  • com.rkmax.myapp.fileprovider
  • com.rkmax.myapp.debug.fileprovider

我的@xml/file_paths定义如下

<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="my_images" path="Android/data/com.rkmax.myapp/files/Pictures" />
</paths>

如果我尝试更改 Picturesfiles/Pictures 之类的内容,我的应用程序会失败

Failed to find configured root that contains/storage/emulated/0/Android/data/com.rkmax.myapp.debug/files/Pictures/20161112_073128-251269360.jpg

如何在文件提供程序路径中定义相对路径?

最佳答案

对于您的特定情况,替换:

<external-path name="my_images" path="Android/data/com.rkmax.myapp/files/Pictures" />

与:

<external-files-path name="my_images" path="Pictures" />

这将需要 24.0.0 或更高版本的支持库,IIRC。

关于android - 如何为具有动态应用程序 ID 的应用程序指定路径外部路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40562942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com