简体   繁体   中英

Starting from Android11, do I need to comply to Android's SAF just to even create a file at public Download location?

I am on Android 11. I just want to be able to create a file in /storage/emulated/0/Download directory on my phone. So, this is the public Download folder that I need to create a file on.

I don't need access to read/modify/delete other files in /storage/emulated/0/Download . i just want my app to be able to create and replace a file of its own at /storage/emulated/0/Download .

Question:

  • Do I need to go by the Storage Access Framework for this?
  • Do I need any special permission for this?
  • Or is it possible get access to /storage/emulated/0/Documents without going through the hassle of Android SAF?

My app is able to create a file at /storage/emulated/0/Download using Android 10 but it fails to do that since Android 11.

My use case is very simple. I just want to create a file at /storage/emulated/0/Download and keep appending more data to the file by replacing it with a new one from time to time.

Do I need to go by the Storage Access Framework for this?

No.

Do I need any special permission for this?

No, though you will need WRITE_EXTERNAL_STORAGE for older devices.

Or is it possible get access to /storage/emulated/0/Documents without going through the hassle of Android SAF?

Environment.getExternalStoragePublicDirectory() is being undeprecated , so it is safe to use that to access Environment.DIRECTORY_DOWNLOADS . That should give you the same access that you have with MediaStore :

  • You can create files there

  • You can read and write your own files 1 there

  • You have no access to other apps' files there

1 For the purposes of this bullet, "your own" refers to your current app installation — if the user uninstalls and reinstalls your app, files from the old installation of your app are no longer considered to be "your own".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM