Forum Xamarin.Forms

Xamarin.Forms: Accessing external storage on Android 11 (target sdk version is 29)

I have an App that has to access external storage (logs, SQLite), and it stopped working (on Android >= 10) since I updated it to Android 10. I found a workaround to set

android:requestLegacyExternalStorage="true"

and it works fine on Android 10 now, but not on Android 11. I heard that this should still work on Android 11 if my app is targeting android 10 (SDK 29), so in my case, it should work. But it doesn't, and I still get deployment failed, permission denied. Anyone already came across this issue?

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    I tested the official sample included in document External storage, and it works properly on emulator (android 11).

    Could you please post a basic demo to github or onedriver so that we can try to reproduce this problem on our side?

    Besides, you can also first check the official document: https://developer.android.com/about/versions/11/privacy/permissions


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • sntntn123sntntn123 Member ✭✭

    I created a new Xamarin.Forms project for reproduction. You have to set target framework to Android 10.
    My addings to Manifest:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <application android:requestLegacyExternalStorage="true" .....></application>
    

    And mainActivity:
    Java.IO.File directory= new Java.IO.File(Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "testest/"));
    This is enough to reproduce the error. It works on Android 10, but not on 11. The funny thing is, it works if I run it in Release mode, but not in Debug.

  • jezhjezh Member, Xamarin Team Xamurai

    I created a new Xamarin.Forms project for reproduction.

    I used the code you provided and tested on the sample code I mentioned above (xamarin android ), but I couldn't reproduce this problem.

    Could you please post a basic demo to github or onedriver so that we can try to reproduce this problem on our side?

  • sntntn123sntntn123 Member ✭✭

    Can you try on Xamarin.Forms (.Droid) instead of Android (Native?)

  • Tracy320Tracy320 Member ✭✭✭

    I tried to create a new xamarin form app, but I haven't reproduce this problem so far, if you upload a demo it will help us solve the problem.

Sign In or Register to comment.