IllegalArgumentException: Failed to find configuration root that contains xxx on FileProvider.getUriForFile

I have been trying to follow the Android tutorial on sharing files. I set up the FileProvider like this:

On the main manifest xml:

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.example.mysecondapp.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true" >
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
        </provider>

the res/xml/filpaths.xml file:

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="myexternalimages" path="SpCars_album/" />
</paths>

And in my code I am trying the following:

File requestFile = new File(mImageFilenames[position]);
                try {
                    fileUri = FileProvider.getUriForFile(
                            SeventhActivity.this,
                            "com.example.mysecondapp.fileprovider",
                            requestFile);
                } catch (IllegalArgumentException e) {
                    Log.e("File Selector",
                            "The selected file can't be shared: " +
                                    mImageFilenames[position]);
                }

The requestFile is instantiated with a proper working path for a file. The path of that file begins exactly with what getExternalFilesDir(Environment.DIRECTORY_PICTURES) returns. I just cant understand what raises the error because everything seems to fit. Thanks in advance.


The path of that file begins exactly with what getExternalFilesDir(Environment.DIRECTORY_PICTURES) returns.

AFAIK, that will not give you a directory named SpCars_album/.

I just cant understand what raises the error because everything seems to fit.

The file you supplied is not one that can be served by the FileProvider from your defined roots.


UPDATE

I forgot that this is tied to a documentation bug on FileProvider. FileProvider and <external-path> does NOT serve files from getExternalFilesDir(), but instead from Environment.getExternalStorageDirectory(). I created a StreamProvider subclass that offers support for getExternalFilesDir().

If you use my StreamProvider, replacing your <external-path> with <external-files-path name="myexternalimages" path="Pictures/SpCars_album/" />, you should have better luck.

IllegalArgumentException on Huawei devices · Issue #496, IllegalArgumentException: Failed to find configuration root that contains xxx on FileProvider.getUriForFile - android. IllegalArgumentException: Failed to find configuration root that contains on FileProvider.getUriForFile Failed to find configuration root that contains xxx on


This is an old question now, but I've just had a similar issue.

A lazy solution I found is to just use:

<external-path name="myexternalimages" path="Android/" />

Because getExternalStorageDirectory returns "/storage/emulated/0/", sharing /Android (the next level down) will allow any files that are in your app to be accessed.

Alternatively, if you want to be more precise, you can do this:

<external-path name="myexternalimages" path="Android/data/YOUR_BUNDLE_ID/files/SpCars_album" />

This doesn't feel quite right, but it does seem to work!

Failed to find configured root that contains "filepath" · Issue #98 , IllegalArgumentException: Failed to find configuration root that contains xxx on FileProvider.getUriForFile. I have been trying to follow the Android tutorial on  IllegalArgumentException: Failed to find configuration root that contains xxx on FileProvider.getUriForFile (3) I have been trying to follow the Android tutorial on sharing files. I set up the FileProvider like this: On the main manifest xml:


Adding implementation 'com.android.support:support-v4:28.0.0' into app gradlle dependencies worked in my case. Please change SDK platform version (28.0.0 in my case) accordingly.

22、Failed to find configured root that contains /storage/emulated/0 , IllegalArgumentException on Huawei devices #496. Closed. aoershov Java.​Lang.RuntimeException: Failed to find configured root that contains /storage/​F0E9-334E/Android/data/com.xxx.ct/files/Pictures/Sample/2018-03-04_050214.​jpg at System.Runtime. FileProvider.GetUriForFile (Android.Content. Dismiss Join GitHub today. GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.


if you dont try catch exception as IllegalArgumentException for FileProvider.getUriFoFile(), when you run your code ,you also will have this exception.

try {
     Uri uriForFile = FileProvider.getUriForFile(this,"com.fengfutong.bluetoothc2s.fileprovider", f);
} catch (IllegalArgumentException e) {
     e.printStackTrace();
}

2. configure the filepaths file, Failed to find configured root that contains "filepath" #98. Closed from plugin java.lang.IllegalArgumentException: Failed to find configured root that contains getUriForFile(FileProvider.java:711) at android.support.v4.content. nativeURL:"​file:///data/user/0/com.xxx/cache/montages.json". I am using  Hi, in my Xamarin Forms application I create pdfs that can be opened with Android application. With device with Android 7 all works fine, now I have tested it with Android 8 and the file can't be open.


flutter_email_sender: Failed to handle method call java.lang , java.lang.IllegalArgumentException: Failed to find configured root that contains getUriForFile(FileProvider.java:739) at android.support.v4.content.FileProvider  Questions: I’m having an issue where I can create a Fragment, its view appears to be created, but it doesn’t show up. The fragment itself is created and any code inside runs without issue, but it is just invisible somewhere.


FileUriExposedException file:///storage/emulated/0/xxx Reason: <provider android:authorities=" Your_application_name .fileprovider" startActivityForResult(intent, requestCode); } private static Uri getUriForFile(​Context context, File IllegalArgumentException: Failed to find configured root that contains  Bug Information Version Number of Plugin: v3.0.1 Device Tested On: Huawei CAM-L21 6.0 Version of VS: 15.6.1 Version of Xamarin: 4.9.0.749 Steps to reproduce the Behavior Sometimes we get IllegalArgumentException to our exception tracking


IllegalArgumentException: Failed to find configured root that contains. I am trying to getUriForFile(FileProvider.java:739) at androidx.core.content.FileProvider. However, this method only get the path of the built-in SD card, so when choosing the pictures in the album from external SD card, can not find the picture address, so threw the exception: failed to find configured root that contains.