Essentials icon indicating copy to clipboard operation
Essentials copied to clipboard

[Bug] Storage permissions Android 13 api 33

Open ChrisDox opened this issue 3 years ago • 103 comments

Description

I have a strange thing when My TARGET ANDROID VERSION is Android 13.0 (API Level 33)

When i use CrossMedia plugin, i want to ask manual permissions to external storage When i do

await Permissions.RequestAsync<Permissions.StorageRead>(); OR
await Permissions.RequestAsync<Permissions.StorageWrite>();

--> NO displayAlert comes to ask permission and the result is always "Denied"

for other asking like Camera, the displayAlert comes normally and it's ok.

To test i use xamarin essential mediaPicker when i do var photo = await MediaPicker.CapturePhotoAsync();

First i have normal alert with "Allow ... to take pictures an record video" After that i have a PermissionException

StorageWrite permission was not granted: Denied
at Xamarin.Essentials.Permissions.EnsureGrantedAsync[TPermission] () [0x00066] in D:\a\_work\1\s\Xamarin.Essentials\Permissions\Permissions.shared.cs:29 
  at Xamarin.Essentials.MediaPicker.PlatformCaptureAsync (Xamarin.Essentials.MediaPickerOptions options, System.Boolean photo) [0x0007e] in D:\a\_work\1\s\Xamarin.Essentials\MediaPicker\MediaPicker.android.cs:59 

.... And NOT storage permission asking alert

WHEN My TARGET ANDROID VERSION is Android 12.1 (API Level 32) ALL WORKS FINE

In my manifest i have

	<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
	<uses-permission android:name="android.permission.CAMERA" />
        .....
        <queries>
            <intent>
              <action android:name="android.media.action.IMAGE_CAPTURE" />
            </intent>
         </queries>

Expected Behavior

Alert with Storage authorization asking

Actual Behavior

PermissionException StorageWrite permission was not granted: Denied

Basic Information

  • Version with issue: xamarin essential 1.7.3

  • Last known good version:

  • IDE: visual studio mac 2022 17.3.3 (build 10)

  • Platform Target Frameworks:

    • Android: 13 api 33
  • Affected Devices: emulator pixel 5 on api 33 , real pixel 6 on api 33

ChrisDox avatar Sep 07 '22 16:09 ChrisDox

This is the case for more type of permissions when targeting API 33.

RemcoDEV avatar Sep 13 '22 06:09 RemcoDEV

Having similar issue on our end. Can someone from the Xamarin team look in this please?

ataparia avatar Sep 23 '22 14:09 ataparia

Sounds like this could be sorted at same time as https://github.com/xamarin/Essentials/issues/2037

plebnz avatar Sep 26 '22 21:09 plebnz

Also still experiencing this issue.

dartur123 avatar Oct 04 '22 02:10 dartur123

We're encountering this issue as well

andycnguyen avatar Oct 06 '22 18:10 andycnguyen

us as well

lazmeister avatar Oct 06 '22 19:10 lazmeister

Same here. You can use following code to reproduce the problem.

public static async Task<bool> HasStorageReadPermissionsAsync()
{
    var permission = await Permissions.CheckStatusAsync<Permissions.StorageRead>();
    // permission is "Denied" if we check for the very first time
    if (permission != PermissionStatus.Granted)
    {
        // The following call should display the permission dialog;
        // It works perfectly fine on <= API 28 but when I run it on API 33, it just returns "Denied"
        // similar to what ChrisDoc documented above.
        var requestStatus = await Permissions.RequestAsync<Permissions.StorageRead>();
        if (requestStatus == PermissionStatus.Granted)
        {
            return true;
        }
    }
    else
    {
        return true;
    }

    return false;
}

thomasgalliker avatar Oct 11 '22 09:10 thomasgalliker

We're also encountering this issue. It appears to make the camera completely unusable on any device using Android 13 (API 33). Has anyone got a workaround for using the camera?

jamesnwarner avatar Oct 21 '22 09:10 jamesnwarner

Hi James,

I've been able to use the camera using the MediaPlugin (last beta version) of James Montemagno.

You can see the post here: https://github.com/jamesmontemagno/MediaPlugin/issues/946

Hope it helps.

El vie, 21 oct 2022 a las 11:15, James Warner @.***>) escribió:

We're also encountering this issue. It appears to make the camera completely unusable on any device using Android 13 (API 33). Has anyone got a workaround for using the camera?

— Reply to this email directly, view it on GitHub https://github.com/xamarin/Essentials/issues/2041#issuecomment-1286686479, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2EYX44ZMQIAS5JM2PBF43WEJNKDANCNFSM6AAAAAAQG6GEL4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

--

Enrique Pereiro Arceredillo I.R.C. MED C.B. 652876023 www.okdicom.com

Este envío es confidencial y está destinado únicamente a la persona a la que ha sido enviado. Puede contener información privada y confidencial. Si usted no es el destinatario al que ha sido remitida, no puede copiarla, distribuirla ni emprender con ella ningún tipo de acción. Si cree que lo ha recibido por error, por favor, notifíquelo al remitente.

This transmission is confidential and intended solely for the person to whom it is addressed. It may contain privileged and confidential information. If you are not the intended recipient, you should not copy, distribute or take any action in reliance on it. If you believe that you have receive this transmission in error, please notify the sender.

okdicom avatar Oct 21 '22 09:10 okdicom

To provide further context to the Xamarin team, since Android 11 (API level 30), the WRITE_EXTERNAL_STORAGE permission does not have any effect on the app's access to storage - https://developer.android.com/training/data-storage#permissions

It appears that on devices using Android 13, the popup dialog to request WRITE_EXTERNAL_STORAGE permission will no longer display. Regardless of whether the code requests it or not.

Therefore it is impossible for users using this version of Android to accept the permission. The fact that the MediaPicker.CapturePhotoAsync() ensures that this permission has been granted means that this method just doesn't work on Android 13.

The Expected Behaviour in the original bug should be that the camera just works, without requiring the WRITE_EXTERNAL_STORAGE permission. That part should be handled in the code if the developer chooses to write the file to storage.

jamesnwarner avatar Oct 24 '22 08:10 jamesnwarner

We're seeing this issue as well.

I was able to use the workaround that okdicom suggested, but that's not ideal since it involves a separate package, and a beta version at that.

brayden-marshall avatar Oct 28 '22 17:10 brayden-marshall

Adding this to the Android manifest may help:

<queries>
  <intent>
    <action android:name="android.media.action.IMAGE_CAPTURE" />
  </intent>
</queries>

It's already in the person's manifest - so no it won't.

Goksly avatar Nov 04 '22 17:11 Goksly

We are also experiencing issues with Android 13 permissions. Will try placing them in the manifest as some have suggested.

tylershelton810 avatar Nov 17 '22 02:11 tylershelton810

I have the same problem, I have given all the permissions, but the permission to use the files does not appear and I cannot request access to the files from the user.

DS2107 avatar Nov 25 '22 13:11 DS2107

Same issue here... a shame that something like this is not fixed asap...

Sebastian1989101 avatar Dec 01 '22 11:12 Sebastian1989101

We are also having the same issue here

it11111111 avatar Dec 01 '22 20:12 it11111111

Hi, Can you try that plugin?

If the problem is not solved, create new issue in that repository. I'll try to fix it.

Don't forget to provide a sample project with this error and the reproduction steps.

dimonovdd avatar Dec 05 '22 22:12 dimonovdd

+1

aismaniotto avatar Dec 09 '22 18:12 aismaniotto

Any updates on this or work around?

softsan avatar Dec 14 '22 14:12 softsan

The Android camera will not work without asking for media permission. On Android 13 when targetting Android 13 the media permission is not asked for making it impossible to use the camera.

Google will require Android 13 as a minumum target version on 1st November 2023.

So unless this issue is fixed, Xamarin.Android and Xamarin.Forms will be End Of Life on 1st November 2023 no matter what date Microsoft claim.

irongut avatar Dec 14 '22 15:12 irongut

I am not sure if this is necessarily a xamarin problem. We are facing the same problem. Before we switched to the xamarin.essentials permission request, we used to open the app settings. There the user had to grant the permission by himself. To come back to the problem, on my OnePlus 8T I cant grant the permissions in the settings. Basically there i cant find the storage permission.

EDIT: We are facing this issue in our file downloader. Up to Android 12 we could simply asked the user for permission to download files. (Therefor we added "READ_EXTERNAL_STORAGE" and "WRITE_EXTERNAL_STORAGE" to our AndroidManifest.)

After searching for a solution for this problem for a whole day, i found that Google wanted to increase the security of the apps for Android 13+. So now the user need to give you the permissions for images, videos and audio files seperatly. Unfortunatly Xamarin.Essentials has not gotten updated yet.

grabnerM avatar Dec 21 '22 14:12 grabnerM

public static async Task AskForRequiredStoragePermission() { try { if (DeviceInfo.Platform == DevicePlatform.Android && DeviceInfo.Version.Major >= 13) { return true; }

            var status = await Permissions.CheckStatusAsync<Permissions.StorageRead>();
            if (status == PermissionStatus.Granted)
            {
                return true;
            }

            if (status == PermissionStatus.Denied && DeviceInfo.Platform == DevicePlatform.iOS)
            {
                // Prompt the user to turn on in settings
                // On iOS once a permission has been denied it may not be requested again from the application
                return false;
            }

            await Permissions.RequestAsync<Permissions.StorageRead>();
            status = await Permissions.CheckStatusAsync<Permissions.StorageRead>();
            if (status == PermissionStatus.Granted)
                return true;
        }
        catch (Exception ex)
        {
            //Something went wrong
        }
        return false;
    }

daesang avatar Dec 27 '22 05:12 daesang

I'm still having this issue; asking for read & write permissions doesn't do anything. No popup, and the permission isn't even listed in the emulator permissions under the app.

eamonnalphin avatar Jan 08 '23 21:01 eamonnalphin

It's working fine after updating to beta version 6.0.1.

Its-AliRaza03 avatar Jan 09 '23 13:01 Its-AliRaza03

image

https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions

I guess doing something like this? But I am not sure if this would work for write scenarios and I couldn't find any permissions for write for these new permissions.

AnthonyWeirbach avatar Jan 10 '23 21:01 AnthonyWeirbach

looks like there is an open pull request to fix this issue.... https://github.com/xamarin/Essentials/pull/2065

AnthonyWeirbach avatar Jan 12 '23 11:01 AnthonyWeirbach

Hopefully the update will be released soon. Currently the only workaround is to target API 32.

programatix avatar Jan 18 '23 03:01 programatix

Please fix this issue! @jfversluis @jamesmontemagno

giuseppenovielli avatar Jan 18 '23 15:01 giuseppenovielli

+1

SHuygh avatar Jan 26 '23 13:01 SHuygh

I'm facing this same issue in my old code. As others suggested, the only option as of now is to target API 32.

NaagAlgates avatar Feb 08 '23 11:02 NaagAlgates