maui: FilePicker doesn't take into account IsExternalStorageManager
Description
When using FilePicker with the permissions: https://developer.android.com/training/data-storage/manage-all-files, I still get a cached file copy rather than the original file path.
My use case is that I am building a document editor and need an easy way to read and write files anywhere on the device file system.
My original issue that this stems from: https://github.com/dotnet/maui/issues/4195 My work around: https://github.com/dotnet/maui/discussions/6004
Steps to Reproduce
Give your application MANAGE_EXTERNAL_STORAGE permissions, as well as special intent: ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION by going into Android settings -> Application Permissions -> Special App Access -> All Files Access -> Enable
Then open the MAUI.Essentials.FilePicker and select a file. The file path returned will be a cached copy.
Version with bug
RC1
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 11 - API 30
Did you find any workaround?
I have managed to work around the issue by creating platform specific file handling, and on android, Im calling the android API directly:
var currentActivity = Platform.CurrentActivity;
// Makes sure the app has ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION before trying to read the file.
if (!Environment.IsExternalStorageManager)
{
var uri = Uri.Parse($"package:{Application.Context?.ApplicationInfo?.PackageName}");
var permissionIntent = new Intent(Settings.ActionManageAppAllFilesAccessPermission, uri);
currentActivity.StartActivity(permissionIntent);
}
var intent = new Intent(Intent.ActionOpenDocument);
intent.AddCategory(Intent.CategoryOpenable);
intent.SetType("application/json");
intent.PutExtra(DocumentsContract.ExtraInitialUri, MediaStore.Downloads.ExternalContentUri);
currentActivity.StartActivityForResult(intent, 1);
And then using the System.IO.File API to write data back to the path returned by the android file select activity.

Relevant log output
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 6
- Comments: 23 (1 by maintainers)
Is there any update on this?
This is a massive pain at the moment.
Youre basically just calling the android API wrappers directly, rather than calling the essentials API. This does mean that you’ll have to write platform specific code to deal with file handling.
Start an activity with the intent to select a file (this will tell the android OS to prompt the user with a native file selection window).
Have your application deal with the activity callback (this is triggered when the user has selected a file in the native file browser). Each activity has a request code / identifier so the consumer knows how to deal with the callback. (I wouldnt use this code in production but it gives you an idea on how to get it to work)
System.IO.FilesHelper.cs
System.IO.File.ReadAllTextAsync(...)/System.IO.File.WriteAllTextAsync(...), assuming that the application has the necessary android permissions to read/write to the file.Hope that helps.
@ac-lap Hope this helps: https://github.com/KieranDevvs/FilePickerIssueWorkaround
You can message me on discord if you have any issues:
KieranDevvs#5374