Android Question File Provider Confusion

Hi guys i just read an example of using File Provider and i used the example app and didnt change anything..

the file was successfully save on the device and opened in PDF Action View (because the file that i used is pdf File) but...

when i open my file manager on my phone the file is nothing there..

1603073315766.png


we can see on the pict that the "shared" folder should be saved in the internal, but i cant found the file, even the "shared" folder is nothing there...

anyone can explain me how its should work?

im sorry i cant attach my example project because the size..

i just copy my code into notepad and txt extension..

cheers!
 

Attachments

  • 1603072084980.png
    1603072084980.png
    27.1 KB · Views: 65
  • FileProvider.txt
    1.5 KB · Views: 83
  • Main.txt
    4.4 KB · Views: 67
Last edited:

JohnC

Expert
Licensed User
Longtime User
How I understand it, is that devices with API level lower then 24 had the ability to easily access/write files to external memory and those files are easily accessible using a file manager.

However, with devices with API level of 24+, google made it harder to access external memory for security reasons. So the preferred method to make a file (of your app) be accessible to other programs would be to use the above "File Provider" code which creates an alias ("Content:/xxxxx") URI that other apps can use to access the file, but this method is NOT compatible with the typical "list files" feature of file managers.

So, if you are on a device that is running API 24+ and your app uses the above file provider code, then any file you "share" is actually located in a local directory to your app and is NOT accessible/viewable by a typical file manager unless the device it rooted (which allows you to view local dirs of apps).

If you want to create a file and have it visible/accessible on the external memory using a file manager on devices running API 24+, then you might be able to use the path returned by File.GetSafeDirDefaultExternal if the device does in fact have "external" memory. But keep in mind that google's latest API 29+ is making it even harder to access external memory at all.
 
Last edited:
Upvote 0
Top