如何使用动态applicationId的应用程序的特定路径外部路径

rkm*_*max 7 android android-fileprovider

我在我的应用程序中使用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>
Run Code Online (Sandbox Code Playgroud)

价值@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>
Run Code Online (Sandbox Code Playgroud)

如果我尝试更改类似的东西Picturesfiles/Pictures我的应用程序失败

Failed to find configured root that contains/storage/emulated/0/Android/data/com.rkmax.myapp.debug/files/Pictures/20161112_073128-251269360.jpg
Run Code Online (Sandbox Code Playgroud)

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

Com*_*are 11

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

<external-path name="my_images" path="Android/data/com.rkmax.myapp/files/Pictures" />
Run Code Online (Sandbox Code Playgroud)

有:

<external-files-path name="my_images" path="Pictures" />
Run Code Online (Sandbox Code Playgroud)

这将需要24.0.0或更高的支持库IIRC.