How to save a file under Maui on Android in MyDocuments?

Tim W 26 Reputation points

I would like to save a file on my Android device. It should be accessible to the user (e.g. by a file browser or simply when plugging the phone into a PC via USB).

FileSystem.AppDataDirectory ist not suitable for this, and Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) keeps mapping to /data/0/user/, which is not accessible by the File Browser app.

Basically: how do I save a file in Android outside the app sandbox?

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,575 questions
0 comments No comments
{count} vote

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 64,001 Reputation points Microsoft Vendor

    how do I save a file in Android outside the app sandbox?

    Firstly, you cannot save files in the external storage, it is related to Storage updates in Android 11, this update comes from native android's design.

    But you can Request All files access. Note: the Google Play store has a policy that limits usage of this permission.

    1.Declare the MANAGE_EXTERNAL_STORAGE permission in the manifest.
    2.Use the ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION intent action to direct users to a system settings page where they can enable the following option for your app: Allow access to manage all files.

    After that, you can save it in /storage/emulated/0/Documents path.

    Best Regards,

    Leon Lu

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful