How to especific path external-path for apps with dynamic applicationId

旧巷老猫 提交于 2019-12-08 19:31:50

问题


I'm using FileProvider in my app, when I take a picture from the app is stored there. also my app have a different application id for debug and release builds

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

I have defined my file provider like this

<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>

the value of @string/authority_file_provider will turn into:

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

and my @xml/file_paths is defined like

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

if I try to changes to something like Pictures or files/Pictures my app fails

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

How I define a relative path in the file provider paths?


回答1:


For your particular case, replace:

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

with:

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

This will require 24.0.0 or higher of the support libraries, IIRC.



来源:https://stackoverflow.com/questions/40562942/how-to-especific-path-external-path-for-apps-with-dynamic-applicationid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!