Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

[Bug] FilePicker permission for storage read doesn't work as intended on Android #1537

Closed
jarkkokoskinen opened this issue Nov 19, 2020 · 2 comments · Fixed by #1555
Closed
Labels
bug Something isn't working
Milestone

Comments

@jarkkokoskinen
Copy link

Description

Recently I started to use Xamarin.Essentials FilePicker for picking files from the file system. When using the FilePicker on Android (Android 10) I noticed that the permission prompt for the storage read permission didn't work properly: When choosing "Deny" from the prompt the file system is still opened, even though it shouldn't. From reading the source code (https://github.com/xamarin/Essentials/blob/main/Xamarin.Essentials/FilePicker/FilePicker.android.cs) it seems that the permission is only asked, but nothing is done with the result (line 19): await Permissions.RequestAsync<Permissions.StorageRead>();.

Steps to Reproduce

  1. Bind the FilePicker PlatformPickAsync method to a button.
  2. Run the application on an Android device (I did this on Android 10).
  3. Press the button that has PlatformPickAsync bound to
  4. From the permission prompt select "Deny"

Expected Behavior

File system doesn't open.

Actual Behavior

File system opens, even though it shouldn't have the right permission. User is still able to navigate the file system and pick files from it.

Basic Information

  • Version with issue: Xamarin.Essentials.1.6.0-pre3
  • Last known good version:
  • IDE: Visual Studio 2019 16.8.1
  • Platform Target Frameworks:
    • Android: 10
  • Affected Devices:
    • Samsung SM-G973F running Android 10 / One UI version 2.5
  • Nuget Packages: Xamarin.Essentials.1.6.0-pre3

Workaround

I was able to create a workaround by prompting the permission alert myself before using the FilePicker class' PlatformPickAsync method by using the Xamarin.Essentials Permission class. This didn't prompt a second permission alert from the FilePicker class on Android 10/Samsung SM-G973F, so it fit for my need at the moment.

@jarkkokoskinen jarkkokoskinen added the bug Something isn't working label Nov 19, 2020
@mattleibow
Copy link
Contributor

I think this is the incorrect method we are using. It should be EnsureGrantedAsync:

await Permissions.EnsureGrantedAsync<Permissions.StorageRead>();

instead of RequestAsync

@mattleibow
Copy link
Contributor

mattleibow commented Nov 19, 2020

I think this will also happen in 3 places due to this same error:

  • picking files on android
  • reading picked files on tizen
  • picking media on android

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants