FileProvider - IllegalArgumentException: Failed to find configured root
Your file is stored under getExternalFilesDir()
. That maps to <external-files-path>
, not <files-path>
. Also, your file path does not contain images/
in it, so the path
attribute in your XML is invalid.
Replace res/xml/file_paths.xml
with:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-files-path name="my_images" path="/" />
</paths>
UPDATE 2020 MAR 13
Provider path for a specific path as followings:
<files-path/>
-->Context.getFilesDir()
<cache-path/>
-->Context.getCacheDir()
<external-path/>
-->Environment.getExternalStorageDirectory()
<external-files-path/>
-->Context.getExternalFilesDir(String)
<external-cache-path/>
-->Context.getExternalCacheDir()
<external-media-path/>
-->Context.getExternalMediaDirs()
Ref: https://developer.android.com/reference/androidx/core/content/FileProvider
FileProvider: Failed to find configured root
The documentation for FileProvider
says that <files-path>
:
Represents files in the
files/
subdirectory of your app's internal storage area. This subdirectory is the same as the value returned byContext.getFilesDir()
.
Your file is not in internal storage. It is in external storage. For that, you need an <external-path>
element, not a <files-path>
element.
FileProvider not working with Failed to find configured root that contains
<paths>
<external-files-path
name="my_docs"
path="docs" />
</paths>
When you specify path as docs
the sub-directories are not included. You get the exception because its not expecting to share the subdirectories. To include them append /
at the end as follows:
<paths>
<external-files-path name="my_docs" path="docs/" />
</paths>
java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Pictures
Change
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="files/"/>
</paths>
to
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="."/>
</paths>
as described in the link you shared above.
The provider below:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="files/"/>
</paths>
will address paths that look like
/storage/emulated/0/files/
but the paths that you are sharing
/storage/emulated/0/Pictures/Polfaced/IMG_20170203_155130.jpg
does not include or starts with:
/storage/emulated/0/files/
To understand what
path="."
does, read the link you shared in detail.
Android: IllegalArgumentException: Failed to find configured root that contains /data/data/
In filepaths.xml
you need
<cache-path name="shared_images_from_glide_cache" path="image_manager_disk_cache"/>
This will result in mapping
new File("/data/data/com.example.glide02/cache/image_manager_disk_cache/5a992029460eed14244e8b970d969d45518b2f7ac10f71eb26bd0aaf7c3bcf06.0")
to
Uri.parse("content://com.example.glide02/shared_images_from_glide_cache/5a992029460eed14244e8b970d969d45518b2f7ac10f71eb26bd0aaf7c3bcf06.0")
(Not sure if I got it exactly right, but you should get the point.)
Android: FileProvider IllegalArgumentException Failed to find configured root that contains /data/data/**/files/Videos/final.mp4
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>
Android: FileProvider.getUriForFile Failed to find configured root
Replace path="Android/data/asmund.thomas.group_project/files/Pictures/"
with path="."
.
File Provider Exception : Failed to find configured root that contains
Replace:
path="Android/data/com.example.app/files"
with:
path="."
<external-files-path>
already points to the location that you are identifying in path
.
Related Topics
Java8 Way to Handle If..Else Check in Collections
How to Send Parallel Get Requests and Wait for Result Responses
Typecasting an Object from Parent Class to Child
How to Get Amount of Tens in a Int
Simpledateformat Producing Wrong Date Time When Parsing "Yyyy-Mm-Dd Hh:Mm"
How to Exclude Classes from Test Coverage Using Java Annotations in Spring Boot
Spring Kafka - How to Reset Offset to Latest With a Group Id
Every Digits in Number of a Range Should Be Is Divisible by N
Java Generics Incompatible Types (No Instance(S) of Type Variable(S) Exist)
How to Compare Two Objects and Find the Fields/Properties Changed
Convert Html/Mxml File to Word Doc Programmatically in Java
Map Json String Column of a JPA Entity to Java Object Automatically
Regex, Remove Whitespace and All Other Characters
Java Spring @Scheduled Tasks Executing Twice
How to Write Unit Test for a Setter Method Which Does Not Have a Getter Method