[英]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.我在 Android 11 上。我只想能够在手机上的
/storage/emulated/0/Download
目录中创建一个文件。 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
.我不需要访问
/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
.我只是希望我的应用程序能够在
/storage/emulated/0/Download
创建和替换它自己的文件。
Question:问题:
/storage/emulated/0/Documents
without going through the hassle of Android SAF?/storage/emulated/0/Documents
而无需经历 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.我的应用程序能够使用 Android 10 在
/storage/emulated/0/Download
创建一个文件,但自 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.我只想在
/storage/emulated/0/Download
处创建一个文件,并通过不时将其替换为新文件来继续将更多数据附加到文件中。
Do I need to go by the Storage Access Framework for this?
为此,我需要存储访问框架 go 吗?
No.不。
Do I need any special permission for this?
我需要为此获得任何特殊许可吗?
No, though you will need WRITE_EXTERNAL_STORAGE
for older devices.不,尽管您需要
WRITE_EXTERNAL_STORAGE
用于旧设备。
Or is it possible get access to /storage/emulated/0/Documents without going through the hassle of Android SAF?
或者是否可以访问 /storage/emulated/0/Documents 而无需经历 Android SAF 的麻烦?
Environment.getExternalStoragePublicDirectory()
is being undeprecated , so it is safe to use that to access Environment.DIRECTORY_DOWNLOADS
. Environment.getExternalStoragePublicDirectory()
不推荐使用,因此使用它来访问Environment.DIRECTORY_DOWNLOADS
是安全的。 That should give you the same access that you have with MediaStore
:这应该为您提供与
MediaStore
相同的访问权限:
You can create files there您可以在那里创建文件
You can read and write your own files 1 there您可以在那里读写自己的文件1
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". 1就本项目符号而言,“您自己的”是指您当前的应用程序安装 - 如果用户卸载并重新安装您的应用程序,则您应用程序的旧安装文件不再被视为“您自己的”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.