简体   繁体   English

WRITE_EXTERNAL_STORAGE可能的目标文件夹

[英]WRITE_EXTERNAL_STORAGE Possible target folders

When having WRITE_EXTERNAL_STORAGE permission, I'd expect to have right to write all over the filesystem (eg. /sdcard , /storage/emulated/0 , /storage/sdcard0 , /mnt/sdcard ,...) 拥有WRITE_EXTERNAL_STORAGE权限时,我希望有权在整个文件系统上进行写(例如/sdcard/storage/emulated/0/storage/sdcard0/mnt/sdcard等)

But because of different internal FS structure, I'm not really able to tell what are allowed folders on target device. 但是由于内部FS结构不同,我无法真正确定目标设备上允许的文件夹。

Currently I use Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) to get downloads folder, but this is in my opinion not the only folder I'm allowed to use. 当前,我使用Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)来获取downloads文件夹,但是我认为这不是我唯一可以使用的文件夹。

So two questions follow: 因此有两个问题:

  1. Is there way to find out what folders I can write wih such permission? 有没有办法找出我可以用这种权限写的文件夹?
  2. When using DownloadManager, are possible target folders sae as for the first question? 使用DownloadManager时,第一个问题可能是目标文件夹吗?

Use Environment.getExternalStorageDirectory() to get available external storage directory. 使用Environment.getExternalStorageDirectory()获取可用的外部存储目录。

You will get the Android external storage directory. 您将获得Android外部存储目录。 This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened. 如果用户已将其安装在计算机上,已从设备中删除或发生了其他问题,则该目录当前可能无法访问。 You can determine its current state with getExternalStorageState() . 您可以使用getExternalStorageState()确定其当前状态。

Note: don't be confused by the word "external" here. 注意:请勿在此处与“外部”一词混淆。 This directory can better be thought as media/shared storage. 最好将此目录视为媒体/共享存储。 It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). 它是一个文件系统,可以保存相对大量的数据,并且可以在所有应用程序之间共享(不强制执行权限)。 Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer. 传统上,这是SD卡,但也可以将其实现为设备中的内置存储,该设备不同于受保护的内部存储,并且可以作为文件系统安装在计算机上。

For android, there's only one external storage, the one it returns via getExternalStorageDirectory() , so you should use that by default. 对于android,只有一个外部存储,它通过getExternalStorageDirectory()返回,因此默认情况下应使用该外部存储。

But, the public mount points usually have a rw permission for user processes, where your app is running, so you can write there as well. 但是,公共挂载点通常对运行您的应用程序的用户进程具有rw权限,因此您也可以在其中写入。 Get root permissions and you can write pretty much anywhere. 获得root权限,您几乎可以在任何地方编写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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