tl;dr: Why do I need a file_paths resource, when I retrieve a file_path dynamically during runtime?
I am currently learning Android Studio by building my own app. What I want to do right now is to take a picture and then get some Text out of it. To take a picture and use it lateron, I followed the Taking Photos Simply guide of the Android Developers. At this point, it is suggested to use a File Provider.
In the manifest, the File Provider is added like this:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mydomain.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
I am struggling with the meta-data
, especially the android:resource=@xml/file_paths"
In the Taking Photos Simply Tutorial, this is the required addition to the XML to make it work:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="Android/data/com.example.package.name/files/Pictures" />
</paths>
So my question is: What is the good practise intended within the developer guide that I should follow, and how do I do that?
Edit: To make things clearer, I am having trouble understanding how to use a resource here at all. This is the method code straigh out of the guide:
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
currentPhotoPath = image.getAbsolutePath();
return image;
}
So I am dynamically getting the name of the file (and therefore it's file path) during the Runtime of my application. What is that file/paths for, I do not understand its usage.