This repository has been archived by the owner on May 15, 2024. It is now read-only.
[Bug][Android] Picking photo from Photos app leads to app crash unless we explicitly request StorageRead permissions on Android 9 #2099
Labels
bug
Something isn't working
Description
After updating our solution to the newest Android 13 supporting packages from Essentials and Forms, and adapting the code to the new expectations regarding permissions, I've found that I could make the photo picker crash with a UnauthorizedAccessException whenever I was on Android 9 and I picked a photo in a certain way.
I cannot reproduce this issue on devices running Android 10 and higher, which I assume is related to changes in permissions that also resulted in previous issues such as the following, which were identified on android 10+:
It is possible that the same issue already existed in older versions of essentials but as there were different expectations regarding permissions, ie we always requested Permissions.StorageRead when picking photos. Now the expectation is that you might not have to explicitly request storage permissions and it seems to still work, except on some older android versions.
Xamarin essentials actually checks for certain permissions before running some of its picking/camera tasks (and some of those checks are even api level dependent), so it is sort of implied that if essentials does not check for a permission, it is likely unnecessary? is there something in the documentation that says we have to request Permissions.StorageRead when picking photos, even though essentials doesn't check for it and it doesn't seem to be necessary for android 10+? is there an exception somewhere that says we have to still request it for android 9 and under?
Steps to Reproduce
Expected Behavior
File is accessible after picking.
Actual Behavior
App will crash with an UnauthorizedAccessException when we attempt to access it.
Basic Information
Reproduction Link
Android's AssemblyInfo.cs file declares:
I just have a plain xaml page with a button that runs this on its clicked event:
The above code will fail on
fr.OpenReadAsync()
when you're on android 9 and you haven't got StorageRead permission. It'll work fine on Android 10+.Workaround
Call
await Xamarin.Essentials.Permissions.RequestAsync<Permissions.StorageRead>();
before running this code, only if your device is running an android version lower than 10.The text was updated successfully, but these errors were encountered: