dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

Camera MediaPicker throws error about write external storage on api 31 #13119

Closed williambuchanan2 closed 1 year ago

williambuchanan2 commented 1 year ago

Description

Using the camera in Maui doesn't seem to work due to permission issues. Using MediaPicker example from the Microsoft documents doesn’t work. Throws error as it tries to access storage.

Error: Microsoft.Maui.ApplicationModel.PermissionException: 'StorageWrite permission was not granted: Denied'

Note that if I don't request StorageWrite permission I get the following error:

Microsoft.Maui.ApplicationModel.PermissionException: 'You need to declare using the permission: android.permission.WRITE_EXTERNAL_STORAGE in your AndroidManifest.xml'

So, bit of a catch 22 situation...

Steps to Reproduce

Do exactly what this page shows:

https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/device-media/picker

Android.Manifest entries:

   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACTION_OPEN_DOCUMENT" />
    <uses-permission android:name="android.permission.ACTION_OPEN_DOCUMENT_TREE" />

    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

    <!-- Required to maintain app compatibility. -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

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

Code:

   private async void TakePhotoPressed()
    {
        MediaPickerOptions options = new MediaPickerOptions();
        options.Title = "Add Attachment";

        FileResult result = await MediaPicker.Default.CapturePhotoAsync(options);
        ...
    }

Link to public reproduction project repository

?

Version with bug

6.0.312

Last version that worked well

Sounds like it has never worked, based on the number of people reporting it.

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

Android api 31

Did you find any workaround?

No

Relevant log output

None
jsuarezruiz commented 1 year ago

Already fixed by https://github.com/dotnet/maui/pull/12914

mattleibow commented 1 year ago

Duplicate of #11275

mattleibow commented 1 year ago

We fixed it a few weeks ago and backported to net7, unfortunately it missed the release so will go out with the next servicing release.

One workaround is to set your app to target one version back: https://github.com/dotnet/maui/issues/11275#issuecomment-1400211776

Very unfortunate to not get this out sooner, I know.