Skip to content

FilePicker doesn't take into account IsExternalStorageManager #6015

@KieranDevvs

Description

@KieranDevvs

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: #4195
My work around: #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.

image
image

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-essentialsEssentials: Device, Display, Connectivity, Secure Storage, Sensors, App Infoplatform/androids/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions