Read/write to Downloads folder denied after targeting Android SDK version 29

480

However, it seems that Android 11 will ignore this flag,

Indeed. It is useless on an Android 11 device. It is only for Android 10 devices.

so it is only a temporary fix.

No because for an Android 10 device it will continue to work.

And for an Android 11 device you dont need it as you can just read the public folders like Download again like before 10.

Share:
480
Sorin Comanescu
Author by

Sorin Comanescu

Updated on December 26, 2022

Comments

  • Sorin Comanescu
    Sorin Comanescu over 1 year

    My Flutter app needs to read from and write to the Download folder (/storage/emulated/0/Download, more precisely).

    Prior to targeting the SDK version 29 (targetSdkVersion 29 in build.gradle), this went well, only by requesting

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion" />
    

    in AndroidManifest.xml.

    To my surprise, after deploying a new version to my phone, the app started to raise access denied errors when trying to access that folder, despite having granted access for the two permissions mentioned above. I suppose this was because I changed the targetSDKVersion to 29.

    The solution was to add android:requestLegacyExternalStorage="true" to the <app> node in AndroidManifest.xml.

    However, it seems that Android 11 will ignore this flag, so it is only a temporary fix.

    So, my question is: what is the right, official, robust way to ensure access to the Download folder for a Flutter app, in the upcoming Android version?

    Usage of the Download folder is a strict requirement.

    Thank you!