Read And Write External storage Permission not working in Android13

Md Mosabbir Alam 20 Reputation points
2023-12-06T13:25:31.46+00:00
  var status = await Permissions.CheckStatusAsync<Permissions.StorageRead>();
  if (status == PermissionStatus.Granted)
  {
      var fileResult = await FilePicker.PickAsync(new PickOptions
      {
          FileTypes = FilePickerFileType.Pdf,
      });

      if (fileResult != null)
      {
          pdfFileName = Path.GetFileName(fileResult.FullPath);
          pdfBytes = File.ReadAllBytes(fileResult.FullPath);
          IsPdfVisible = true;
      }

      {
          var requestStatus = await Permissions.RequestAsync<Permissions.StorageRead>();
          if (requestStatus == PermissionStatus.Granted)
          {
              var fileResult2 = await FilePicker.PickAsync(new PickOptions
              {
                  FileTypes = FilePickerFileType.Pdf,
              });

              if (fileResult != null)
              {
                  pdfFileName = Path.GetFileName(fileResult2.FullPath);
                  pdfBytes = File.ReadAllBytes(fileResult2.FullPath);
                  IsPdfVisible = true;
              }
          }
          else
          {
              await ToastHelper.ShowToast("Please grant permission to access storage..");
          }
      }
  }

This is my code ,I am using .NET MAUI with .NET7,My android:targetSdkVersion="33", I want to pick pdf from device ,In my android12 device all are working good but what permission do we use for android 13, When i use ReadMediaImage permission instead of Storage read i get an error (doesn't exists in the current context).

Developer technologies | .NET | .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-12-07T03:23:30.65+00:00

    Hello,

    After Android 13, Google further refined the permission management of external storage.

    Please refer to File picker for more details.

    If your app targets Android 12 or lower, you must request the READ_EXTERNAL_STORAGE permission. If your app targets Android 13 or higher and needs access to files that other apps have created, you must request one or more of the following granular permissions instead of the READ_EXTERNAL_STORAGE permission: READ_MEDIA_IMAGES READ_MEDIA_VIDEO READ_MEDIA_AUDIO

    Best Regards,

    Alec Liu.


    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.


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.