StorageRead and StorageWrite Permissions Denied.

Asgar Ali 86 Reputation points
2023-12-19T04:25:42.29+00:00

I am getting a storageRead and storagewrite permissions denied on this code.

The pop ups for these permissions are also not showing up.

public async Task<bool> CheckCameraStoragePermissions()
{
    bool bool1 = false , bool2 = false,  bool3 = false;
    var status1 = await Permissions.CheckStatusAsync<Permissions.Camera>();
    var status2 = await Permissions.CheckStatusAsync<Permissions.StorageWrite>();
    var status3 = await Permissions.CheckStatusAsync<Permissions.StorageRead>();
    
    if(status1 != PermissionStatus.Granted)
    {
        var result1 = Permissions.RequestAsync<Permissions.Camera>();
        status1 = result1.Result;
       bool1 = status1 == PermissionStatus.Granted;

    }
    if (status2 != PermissionStatus.Granted)
    {
        var result1 = Permissions.RequestAsync<Permissions.StorageWrite>();
        status2 = result1.Result;
        bool2 = status2 == PermissionStatus.Granted;
    }

    if (status3 != PermissionStatus.Granted)
    {
        var result1 = Permissions.RequestAsync<Permissions.StorageRead>();
        status3 = result1.Result;
        bool3 = status3 == PermissionStatus.Granted;
    }




    return bool1 && bool2 && bool3;
}
Developer technologies | .NET | Xamarin
Developer technologies | C#
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-12-21T06:29:30.76+00:00

    Hello,

    just one little doubt will the solution (Permissions. Photos) work for previous android versions.?

    For Android permissions, you need to apply for different permissions according to different versions.

    Please refer to the following steps:

    Step 1. Modify Platforms/Android/AndroidManifest.xml in your project:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
    <uses-permission android:name="android.permission.WRITE_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" />
    

    Step 2. When requesting permissions, you could request the corresponding permissions by judging the Android version.

    #if ANDROID
                if (Build.VERSION.SdkInt >= BuildVersionCodes.Tiramisu) // Check whether the Android version is Android 13 or later
                {
                    // request media permissions
                }
                else
                {
                    // request stroage permissions.
                }
    #endif
    

    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.