Search code examples
c#xamarin.formsandroid-11

How to pick a .xml file on android 11?


I am trying to select a file from an external storage on Android 11. I got read and write permissions, as well as ActionManageAllFilesAccessPermission. It doesn't work

var file = await CrossFilePicker.Current.PickFile();

Help me please =(


Solution

  • For now, we use File Picker of Xamarin.Essentials to pick a single or multiple files from the device.

    Install Xamarin.Essentials NuGet package.

    Update Android Manifest:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    

    Replace:

    var file = await CrossFilePicker.Current.PickFile();
    

    To:

    var file = await FilePicker.PickAsync(PickOptions.Default);
    

    After allowing the permissions, you could pick the file you want.

    enter image description here

    For more details about the File Picker, please check the MS document. https://learn.microsoft.com/en-us/xamarin/essentials/file-picker?tabs=android