Android FileProvider: Can I view/share file from Downloads /Documents /DCIM Folders?

52 Views Asked by At

I have pdf files in Downloads Folder: Environment.DIRECTORY_DOWNLOADS+File.separator+"MyFolder". Listed the files I need in a Recyclerview. I need to view any selected file in any pdfviewer, using intent.

Created a FileProvider with this xml

 <external-path name="download_files" path="Download/" />

This is the error I get:

java.lang.IllegalArgumentException: Failed to find configured root that contains /Download/MyFolder/My File.pdf

This is how I've created the Uri and the intent:

File file = new File(downloadPath  +File.separator+ fileName); 
Uri fileUri = FileProvider.getUriForFile(context,"my.app.provider", file);
Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(fileUri, mediaType);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

So my question again: Can one view or open a file from the ExternalPublicDirectories such as Downloads, Documents or DCIM?

or must the files be in Android>data>com.my.app>?

0

There are 0 best solutions below