Search code examples
androidmauimaui-community-toolkit

Issues with READ_EXTERNAL_STORAGE Permission in .NET MAUI 8


I'm working on a .NET MAUI 8 application and I'm facing an issue with accessing external storage. I need to read files from external storage, but my attempts to request the READ_EXTERNAL_STORAGE permission are failing.

Here's what I've tried so far:

Requesting Permission: I have implemented the permission request logic for READ_EXTERNAL_STORAGE, but it is being denied immediately. Permission Status Check: I checked the permission status and it's being reported as denied, even though other permissions work fine. GitHub Solution: I followed a solution from this GitHub repository, but it didn't resolve the issue. (https://github.com/dotnet/maui-samples/tree/main/8.0/PlatformIntegration/PlatformIntegrationDemos)

What I've done:

I have ensured that I added the necessary permission in the Android AndroidManifest.xml file. I have handled permission requests and status checks according to the documentation.

Code snippets:

AndroidManifest.xml <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> Permission Request Code:


var status = await Permissions.RequestAsync<Permissions.StorageRead>();
if (status != PermissionStatus.Granted)
{
    // Handle the denied permission case
}

My environment:

.NET MAUI version: 8 Target Android version: 14

minimum Android version 5

Can someone help me figure out why the READ_EXTERNAL_STORAGE permission is being denied in my .NET MAUI 8 app? Are there any additional steps or configurations required to successfully request and use this permission? Any insights or solutions would be greatly appreciated!


Solution

  • For the target android 13, the <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> has been removed, so the dialog about permission request will never appear on the android 13 or higher. The value of the Permissions.RequestAsync<Permissions.StorageRead> will always be PermissionStatus.Denied.

    But as a workaround, you can change your application's target android version to the android 12 to make the READ_EXTERNAL_STORAGE permission request alert still appear on the device with android 13 or higher. Add the following code in the AndroidManifest.xml:

     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
     <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
    

    Note:

    And there are some relative issues, you can follow up them here:

    Permissions CheckStatusAsync Or CheckStatusAsync returns Denied instead of restricted

    Permission bug: Bluetooth scanning without location permission on Android 12+