-
Notifications
You must be signed in to change notification settings - Fork 505
[Bug] Storage permissions Android 13 api 33 #2041
Comments
This is the case for more type of permissions when targeting API 33. |
Having similar issue on our end. Can someone from the Xamarin team look in this please? |
Sounds like this could be sorted at same time as #2037 |
Also still experiencing this issue. |
We're encountering this issue as well |
us as well |
Same here. You can use following code to reproduce the problem.
|
We're also encountering this issue. |
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:
jamesmontemagno/MediaPlugin#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
<#2041 (comment)>,
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.
|
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 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. |
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. |
It's already in the person's manifest - so no it won't. |
We are also experiencing issues with Android 13 permissions. Will try placing them in the manifest as some have suggested. |
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. |
Same issue here... a shame that something like this is not fixed asap... |
We are also having the same issue here |
Adds Granular media permissions for Android 13+ https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions
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. |
+1 |
Any updates on this or work around? |
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. |
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. EDIT: 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. |
public static async Task AskForRequiredStoragePermission()
|
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. |
It's working fine after updating to beta version 6.0.1. |
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. |
Well, there seems to be a answer here at the bottom of this thread, and also some feedback from a member of Xamarin team, and their 'response' which was "As mentioned in #2063 (comment) also about permissions, Xamarin.Essentials is in maintanance only and we're not looking to add new functionality unless we absolutely have to. New development will happen in .NET MAUI." REF: #2065 |
OK - it's a simple fix to get around this, and it's working ok for me on API33. You only have to update the following method, and then add the manifest entries - and your camera operations are working again on API 33.
Credit to @WanftMoon on this post (#2065) for pointing me in the right direction. Camera operations restored in API 33 - thank you. |
Did you get this working in a release-version? It works for me, but only in debug. As if somethings wrong with the manifest-file. |
I published it to a release version, assuming it would work.. after testing with a debug version. I think I'll report back here and double check it's working post release.. thanks.
Kind Regards,
Jeffrey Holmes
+66806075331
…________________________________
From: Daniel Halme Ståhlberg ***@***.***>
Sent: Friday, September 15, 2023 6:20:02 PM
To: xamarin/Essentials ***@***.***>
Cc: Jeffrey Holmes ***@***.***>; Comment ***@***.***>
Subject: Re: [xamarin/Essentials] [Bug] Storage permissions Android 13 api 33 (Issue #2041)
OK - it's a simple fix to get around this, and it's working ok for me on API33.
You only have to update the following method, and then add the manifest entries - and your camera operations are working again on API 33.
1. Android Main Activity updat the following Method to this.. (This tricks Android to accept a permission on a platform where it's no longer used - lol )
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
if (Xamarin.Essentials.DeviceInfo.Version.Major >= 13 && (permissions.Where(p => p.Equals("android.permission.WRITE_EXTERNAL_STORAGE")).Any() || permissions.Where(p => p.Equals("android.permission.READ_EXTERNAL_STORAGE")).Any()))
{
var wIdx = Array.IndexOf(permissions, "android.permission.WRITE_EXTERNAL_STORAGE");
var rIdx = Array.IndexOf(permissions, "android.permission.READ_EXTERNAL_STORAGE");
if (wIdx != -1 && wIdx < permissions.Length) grantResults[wIdx] = Permission.Granted;
if (rIdx != -1 && rIdx < permissions.Length) grantResults[rIdx] = Permission.Granted;
}
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
2. Manifest File
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!--<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />-->
<uses-feature android:name="android.hardware.location" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
<uses-feature android:name="android.hardware.location.network" android:required="false" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
Credit to @WanftMoon<https://github.com/WanftMoon> on this post (#2065<#2065>) for pointing me in the right direction. Camera operations restored in API 33 - thank you.
Did you get this working in a release-version? It works for me, but only in debug. As if somethings wrong with the manifest-file.
—
Reply to this email directly, view it on GitHub<#2041 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABJ4KG2FQD4UKZR2MGPHEFTX2Q2WFANCNFSM6AAAAAAQG6GEL4>.
You are receiving this because you commented.Message ID: ***@***.***>
|
@leffemedkniven Hi there - i've just reinstalled a release version, and confirmed this method above works ok. With what i have posted above, on startup, i have a check for permissions that requests the following.
|
When adding this to the PageModel it doesn't pop-up at all, only in debug. Trying to add it to MainActivity.OnCreate doesn't work because it's not async. Tried this in MainActivity aswell:
It pops up in release, I allow it, but it doesn't work when trying to add pictures to external storage. |
I actually don't request permission for ReadMediaImages explicity during runtime, this is handled already in my manifest file without having to request it. The permissions above that i'm requesting i've already included in the above post. |
does this mean that we don't need permission to write in android 13 onwards? we can directly write if required? if yes than how is this increasing security? |
So in the Android manifest, did you end up commenting out the old permissions (READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE)? And so this means you no longer need to check And you still need the code below also? public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
if (Xamarin.Essentials.DeviceInfo.Version.Major >= 13 && (permissions.Where(p => p.Equals("android.permission.WRITE_EXTERNAL_STORAGE")).Any() || permissions.Where(p => p.Equals("android.permission.READ_EXTERNAL_STORAGE")).Any()))
{
var wIdx = Array.IndexOf(permissions, "android.permission.WRITE_EXTERNAL_STORAGE");
var rIdx = Array.IndexOf(permissions, "android.permission.READ_EXTERNAL_STORAGE");
if (wIdx != -1 && wIdx < permissions.Length) grantResults[wIdx] = Permission.Granted;
if (rIdx != -1 && rIdx < permissions.Length) grantResults[rIdx] = Permission.Granted;
}
Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
} Do you need any other changes to fix it? And know if this would still work with a min SDK of <33 specified? Or did you just specify both min SDK and target SDK as 33? |
I can confirm that this works for Android 13: public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
but, I cannot remove the old permissions from the Manifest nor set android:maxSdkVersion= because the plugin will fail when calling CheckStatusAsync. |
Did you extend the permissions?
|
In addition to the manifest changes, I found it simpler to create a subclass of StorageRead and put the sdk check there:
Then use ReadMedia permission class anywhere I would use StorageRead. |
Know when this base permission class functionality would/should be needed? Because with just simply using the code below, I'm able to upload photos on Android 13, 12, and 10 just fine. So it seems the above code isn't needed (unless I'm missing a scenario)...
My manifest
|
This worked for me
|
Which is the Platform library? |
the one from Xamarin.Essentials
|
Does any one found solution for this, I am getting same error? |
Yeah, if you look at the previous messages, the solution is more or less:
|
Can someone help me solve the storage permission error, create a test app and I need to know what the code would be to request permission in Android 13. My mainactivity is using Android.App; namespace MvvmPrueba.Droid
} |
Scroll up.. there are examples there. look @ #2041 (comment) |
already add the following permissions |
1 similar comment
already add the following permissions |
@juanes030 with that said, i would recommend that you use at least these
|
I think this has been fixed by #2073. Worked for me by updating to Xamarin Essentials 1.7.5 |
I found an easy solution. You don't need anything from above:
Fixed. Now the file picker behaves as expected ! Why ? Dunno why an older version of xamarin essentials is used by the android project (even when built by appcenter !). I verified and it's 1.8.0 everywhere. |
Xamarin Essentials 1.8 alone definitely doesn't fix the problem. You need one of the workarounds described earlier in this issue. If your app targets SDK 33 or higher, the app needs to request the READ_MEDIA_IMAGES permission. |
Not necessarily. |
what if um not working with media files, just a document/pdf file that I need to download, |
its working perfectly fine
|
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
--> 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
....
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
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:
Affected Devices: emulator pixel 5 on api 33 , real pixel 6 on api 33
The text was updated successfully, but these errors were encountered: