Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 223
NitZRobotKoder Avatar asked Jul 10 '15 15:07

NitZRobotKoder


2 Answers

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>
like image 122
CommonsWare Avatar answered Oct 24 '22 08:10

CommonsWare


change your provider XML to this.

<?xml version="1.0" encoding="utf-8"?>
<paths>
  <external-path name="external_files" path="." />
  <root-path name="external_files" path="/storage/" />
</paths>
like image 11
Vishal Sorathiya Avatar answered Oct 24 '22 09:10

Vishal Sorathiya