Forum Xamarin.Android

File Access Permission

I want read a file in external storage with mi app, I request storage permission:

if (!(await CrossPermissions.Current.CheckPermissionStatusAsync<StoragePermission>()).Equals(PermissionStatus.Granted)) { if(await CrossPermissions.Current.RequestPermissionsAsync(Permission.Storage))[Permission.Storage].Equals(PermissionStatus.Granted)) { return true; } else { return false; } }

This message apparence:

Not say "files" like this:

So for that when i try read file, UnauthorizedException is invoked.

¿Any solution?



  • XamarinProblemsXamarinProblems Member ✭✭
    edited February 17

    @eliseogamba I'm guessing, but in your Android Manifest do you only have this?

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

    If so, try adding:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  • eliseogambaeliseogamba Member ✭✭

    Hi XamarinProblems,

    I already have it.

  • XamarinProblemsXamarinProblems Member ✭✭
    edited February 17

    @eliseogamba, Hmm okay, I opened up a project of my own where i recalled making use of the CrossPermission plugin, the only difference between my code and yours would be when we ask for the storage permission my code does it with

    var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Storage });
    var status = results[Permission.Storage];

    I do however get the dialog you are looking for where it requests for access to files. Im using version, might have something to do with it.

  • jezhjezh Member, Xamarin Team Xamurai

    We couldn't reproduce this question ,but you can check the sample of PermissionsPlugin first.

    If it is convenient for you ,could you please post a basic demo so that we can try to test on our side?

  • eliseogambaeliseogamba Member ✭✭

    @XamarinProblems I try with your code but still the same.

  • eliseogambaeliseogamba Member ✭✭

    @jezh I check your repo and i dont be nothing diferrent that you. I change version package to 2.2.1 (that you use) and that use @XamarinProblems but nothing. Same problem

  • @eliseogamba, then im all out of ideas, I'd say that last place we havent talked about is the settings on the phone, I pressume you have done this but removing the app completely and installing it again might reset some internal phone settings for the access to files for your app. If that dosen't work then, then i can't help you and hope someone else can.

  • eliseogambaeliseogamba Member ✭✭


    I found problem.

    The problem appears when setting Android: targetSdkVersion greater than 28 (29 for Android 10). When I put android: targetSdkVersion = 28 then it works correctly.
    It must be an Android 10 problem, do you have any idea where it should come from?

  • BrendanZagaeskiBrendanZagaeski USForum Administrator, Xamarin Team Xamurai
    edited February 19
Sign In or Register to comment.