Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ANDROID] Requesting Read-Write External Storage in .net 7 not working #14729

Closed
tataelm opened this issue Apr 23, 2023 · 9 comments · Fixed by #23909
Closed

[ANDROID] Requesting Read-Write External Storage in .net 7 not working #14729

tataelm opened this issue Apr 23, 2023 · 9 comments · Fixed by #23909
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info fixed-in-8.0.90 fixed-in-9.0.0-rc.2.24503.2 platform/android 🤖 t/enhancement ☀️ New feature or request
Milestone

Comments

@tataelm
Copy link

tataelm commented Apr 23, 2023

Description

"android.permission.READ_EXTERNAL_STORAGE" and "android.permission.WRITE_EXTERNAL_STORAGE" can't be requested. I have tried adding it under AndroidManifest.xml and adding it as assembly under MainActivity.cs but no use.

Besides "ShouldShowRationale" not getting triggered, I can't change the permissions manually neither because there is none.

Steps to Reproduce

  1. Create a brand new project with .net 7.
  2. Add these under AndroidManifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  1. Add a method on main page and trigger it via button click
 public async Task CheckForPermissions()
    {               
        var status_write = await Permissions.CheckStatusAsync<Permissions.StorageWrite>();
        var status_read = await Permissions.CheckStatusAsync<Permissions.StorageRead>();

        if (Permissions.ShouldShowRationale<Permissions.StorageWrite>())
        {
            // just testing
        }

        if (Permissions.ShouldShowRationale<Permissions.StorageRead>())
        {
            // just testing
        }

        status_write = await Permissions.RequestAsync<Permissions.StorageWrite>();
        status_read = await Permissions.RequestAsync<Permissions.StorageRead>();

        if (status_write != PermissionStatus.Granted)
        {
            // still not granted
        }

        // forward user to settings so they can grant permission
        AppInfo.Current.ShowSettingsUI();
    }
  1. You will be forwarded to application settings and you won't find any permission requests.

Link to public reproduction project repository

none

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android api 33

Did you find any workaround?

No response

Relevant log output

No response

@tataelm tataelm added the t/bug Something isn't working label Apr 23, 2023
@moljac
Copy link
Contributor

moljac commented Apr 24, 2023

Can confirm. Under further investigation.

Repro sample:

AppMAUI.Issue14729.PermissionsExternalStorage.zip

net7.0

API App Permissions
33 Screenshot_1682337756 Screenshot_1682337766
32 Screenshot_1682338714 Screenshot_1682338718 Screenshot_1682338743

net6.0

API App Permissions
33 Screenshot_1682336890 Screenshot_1682336895 Screenshot_1682336903

@jsuarezruiz jsuarezruiz added the area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label Apr 24, 2023
@mattleibow
Copy link
Member

mattleibow commented Apr 24, 2023

There is this issue: #12857
And this PR: #12766

We added this code:

if (!OperatingSystem.IsAndroidVersionAtLeast(33))
    await Permissions.EnsureGrantedAsync<Permissions.StorageWrite>();

Maybe we need to make the request do nothing on 33+ and just return granted always?

In Android 13+ android.permission.WRITE_EXTERNAL_STORAGE no longer exists, and requesting it always returns Denied.

@mattleibow mattleibow added t/enhancement ☀️ New feature or request and removed t/bug Something isn't working labels Apr 24, 2023
@mattleibow mattleibow added this to the Backlog milestone Apr 24, 2023
@ghost
Copy link

ghost commented Apr 24, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@Laim
Copy link

Laim commented Apr 29, 2023

Having the same issue, very annoying. Was hoping to let users backup their database to wherever they wanted but seems to be near impossible to get working on .NET 7 against API 33 at the moment.

@mosabbir786
Copy link

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.
Is this issue resolved or not

@Kapusch
Copy link

Kapusch commented Dec 18, 2023

Hi @tataelm , I know this may not be ideal for you, but I think this has been fixed in .NET 8.
Did you give it a try?

@MattePozzy
Copy link

MattePozzy commented Jan 19, 2024

Android 14 .net 8
PermissionStatus storageStatus = await Permissions.CheckStatusAsync<Permissions.StorageWrite>();
return always false.
In manifest is
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />.

@CallumHoughton
Copy link

CallumHoughton commented May 1, 2024

This is still an issue - it returns denied for both StorageRead and StorageWrite on Android 14. Though on Android now accessing the file system should mean you go through Storage Access Framework and and the MediaStore (which require platform specific setup that we've had to implement ourselves)

@Fiontan
Copy link

Fiontan commented Jun 19, 2024

This is an issue for us in a migration from Xamarin forms and is becoming a bit of a showstopper. We've followed all the recommendations for the manifest. Taking/uploading images and videos kind of works (we are also seeing a significantly awful degradation in performance for encrypted files but that's a different story although who knows if it's related or not), but as soon as a user tries to upload from "File manager" (and not pics/vids):
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info fixed-in-8.0.90 fixed-in-9.0.0-rc.2.24503.2 platform/android 🤖 t/enhancement ☀️ New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.