Android: FileProvider IllegalArgumentException Failed to find configured root that contains /data/data/**/files/Videos/final.mp4

NitZRobotKoder picture NitZRobotKoder · Jul 10, 2015 · Viewed 45.4k times · Source

I am trying to use FileProvider to play a video from private path.Facing

java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/XXXXX(Package)/files/Videos/final.mp4

Code:

<paths>
    <files-path path="my_docs" name="Videos/" />
</paths>

Java code:

File imagePath = new File(getFilesDir(), "Videos");
File newFile = new File(imagePath, "final.mp4");
Log.d(TAG, "-------------newFile:"+newFile.exists());//True here
//Exception in below line
Uri contentUri = FileProvider.getUriForFile(this,"com.wow.fileprovider", newFile);

Manifest.xml

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="com.wow.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">

<meta-data
    android:name="android.support.FILE_PROVIDER_PATHS"
    android:resource="@xml/file_paths" />

Any clues on this?

Thanks Nitz

Answer

CommonsWare picture CommonsWare · Jul 10, 2015

You have your name and your path flipped. name is what goes in the Uri, and path is the relative location within the root on the filesystem.

Go with:

<paths>
    <files-path name="my_docs" path="Videos/" />
</paths>