FilePicker.PickAsync Xamarin essentials API not working for Android 13

rmpQue 6 Reputation points
2023-08-23T08:48:23.0866667+00:00

FilePicker working fine for below android 13, but getting permission exception for android 13.

Xamarin.Essentials.PermissionException: StorageRead permission was not granted: Denied
  at Xamarin.Essentials.Permissions.EnsureGrantedAsync[TPermission] () [0x00066] in D:\a\1\s\Xamarin.Essentials\Permissions\Permissions.shared.cs:29 
  at Xamarin.Essentials.FilePicker.PlatformPickAsync (Xamarin.Essentials.PickOptions options, System.Boolean allowMultiple) [0x0001d] in D:\a\1\s\Xamarin.Essentials\FilePicker\FilePicker.android.cs:16 
  at Xamarin.Essentials.FilePicker.PickAsync (Xamarin.Essentials.PickOptions options) [0x0001c] in D:\a\1\s\Xamarin.Essentials\FilePicker\FilePicker.shared.cs:12 

Developer technologies | .NET | Xamarin
{count} vote

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2023-08-24T04:50:36.0733333+00:00

    Hello,

    First of all, please check whether the permissions are missing or not.

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
    <!-- Required only if your app needs to access images or photos that other apps created -->
    
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    
    <!-- Required only if your app needs to access videos that other apps created -->
    
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
    
    <!-- Required only if your app needs to access audio files that other apps created -->
    
    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
    

    Then please make sure you've updated Essentials to version 1.7.5 or later. I can reproduce the issue with Essentials 1.7.0 even though I set the permissions.

    For more details, please refer to File picker - .NET MAUI | Microsoft Learn.

    (Currently, Xamarin.Essentials is a part of MAUI, and this doc is about MAUI.

    Xamarin.Essentials: File Picker doc doesn't point out permission issue, please see the similar issue at GitHub- [Bug] Storage permissions Android 13 api 33 · Issue #2041)

    Best Regards,

    Wenyan Zhang


    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.