One more of these FileProvider lost souls... I have been working on this problem more than a day now, and it seems I am missing something big. Any help would be appreciated!
I am trying to send email with attachment using FileProvider.
The part of my AndroidManifest.xml:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="todolistj.todolist.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
file_paths.xml:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="lists_to_send" path="export/"/>
</paths>
Creating the attachment:
String content = "hello world";
File file;
FileOutputStream outputStream;
try {
File dir = context.getExternalFilesDir("export");
if(!dir.exists()) dir.mkdir();
file = new File(dir, "MyCache");
if (file.exists ()) file.delete ();
outputStream = new FileOutputStream(file);
outputStream.write(content.getBytes());
outputStream.close();
return file.getAbsolutePath();
} catch (IOException e) {
e.printStackTrace();
}
And the Uri creation:
File readF = new File(fullFileName);
Uri uri = FileProvider.getUriForFile(this, "todolistj.todolist.fileprovider", readF);
where fullFileName
is the value returned in the snippet for file creation.
On the Uri creation line I get exception:
...
Caused by: java.lang.IllegalArgumentException: Failed to find configured
root that contains /storage/emulated/0/Android/data/todolistj.todolist/files/export/MyCache
...
As the documentation here (https://developer.android.com/reference/android/support/v4/content/FileProvider.html) states:
< external-files-path name="name" path="path" /> Represents files in the root of your app's external storage area. The root path of this subdirectory is the same as the value returned by Context#getExternalFilesDir(String) Context.getExternalFilesDir(null).
So external-files-path from my xml seems to match the context.getExternalFilesDir
method I am using.
Both places I have the "export" folder. Authorities seem to match... What could be my problem. I found no way to find and print FileProvider's "configured root"