I have set a FileProvider with the following res/xml/file_paths.xml
:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="suggestions" path="Android/data/com.example.app.dev/files/suggestions" />
</paths>
The problem is, I have many product flavors that change the applicationId
. Is there any way to replace that value with the proper applicationId without creating a filepath for each product flavor? Like replacing a tag like this Android/data/{appId}/files/suggestions
? Or even using a relative path... (I've tried everything but only this full path worked).
I managed to solve this issue by using Gradle to dynamically create a string resource value in the build.gradle file to represent the file path:
defaultConfig {
applicationId "com.example.myapp"
...
resValue 'string', 'images_file_path', "Android/data/" + applicationId + "/files/Pictures"
}
You can then reference this string resource value in the res/xml/file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" android:path="@string/images_file_path" />
</paths>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With