I'm developping a .net maui application and I'm facing a problem when requesting permissions in Android 14. For some reason when I use "Permissions.RequestAsync()" the dialog box doesn't appear in Android 14, I used Android 12 emulators and an android 11 physical device and both worked as espected. The weird thing is that the permissions doesn't even show in the Settings of the device.
Here is my code:
public static async Task<bool> HasStoragePermission()
{
PermissionStatus status = await Permissions.CheckStatusAsync<Permissions.StorageWrite>();
PermissionStatus status2 = await Permissions.CheckStatusAsync<Permissions.StorageRead>();
return status == PermissionStatus.Granted && status2 == PermissionStatus.Granted;
}
public static async Task<bool> RequestPermissionStorage()
{
var status2 = await Permissions.RequestAsync<Permissions.StorageRead>();
var status = await Permissions.RequestAsync<Permissions.StorageWrite>();
return HasStoragePermission().Result;
}
And here is my android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true" android:usesCleartextTraffic="true">
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
From 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
. This is also the case with Permissions.StorageRead
.
But as a workaround, you can change your application's target android version to the android 12 to make the READ_EXTERNAL_STORAGE
and WRITE_EXTERNAL_STORAGE
permission request alert will still appear on the device with android 13 or higher.
So you can try to add the following code in the AndroidManifest.xml
:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- add the code below -->
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
Note:
And there is a relative issue, you can follow it up here:
Permissions CheckStatusAsync Or CheckStatusAsync returns Denied instead of restricted