Android: how to add an xml file to res/xml

Hi there,

I need to provide file access between my app and the photo’s app. What I’m trying to do is load a photo from the gallery or camera.

This used to work until I upgraded to 24 when I ran into a permissions problem.

The solution seems to be to identify my app as a FileProvider - as described here:

However I’m not sure how to approach:

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <files-path name="my_images" path="images/"/>
    <files-path name="my_docs" path="docs/"/>
</paths>

Put the <paths> element and its children in an XML file in your project. For example, you can add them to a new file called res/xml/file_paths.xml.

Seems that I could modify the apk post build but this is going to get old fast. Perhaps there’s a location I can put the file in the build directory or elsewhere and get it copied across when packaging?

I can see the build system moving files around in UEDeployAndroid, and also that the APL contents appear in the Intermediate folder.

Two questions I guess:

  1. If I copy a file to the relevant
    place in Intermediate does it
    magically appear in the APK

  2. How do I copy a source file to
    Intermediate during the build
    procress? It looks like file copying
    is in the core deployment cs files
    but not the plugin cs files so I’m hoping that I can add files to a
    list somewhere with a desired
    destination.

Dealing with this in a plugin scenario, assuming that you already added the _APL.xml file in your build.cs, put the file_paths.xml in the same folder as the APL.xml file and you can add this code to your (filename)_APL.xml

     <root xmlns:android="http://schemas.android.com/apk/res/android">
     ...
           <!-- optional files or directories to copy to Intermediate/Android/APK -->
          <resourceCopies>
              <copyFile src="$S(ProjectDir)/Plugins/(YourPlugin)/Source/(YourPlugin)/file_paths.xml"
        				dst="$S(BuildDir)/res/xml/file_paths.xml" />
          </resourceCopies>
</root>