简体   繁体   English

Android-查找所有内部和外部存储

[英]Android - Find all internal and external storage

So I've noticed that from device-to-device, there are many different configurations for internal vs. external. 因此,我注意到从设备到设备,内部和外部都有许多不同的配置。 On my Evo there's just internal storage and the external SD card, but on a Droid Incredible from the same year, there's internal storage, internal SD card (~8GB) and external SD card (default 1GB). 在我的Evo上,只有内部存储器和外部SD卡,但是在同一年的Droid Incredible上,有内部存储器,内部SD卡(约8GB)和外部SD卡(默认为1GB)。 Presumably there are other configurations as well, and there will be more forthcoming. 大概还有其他配置,并且还会有更多配置。

However, all I can seem to find about enumerating the number of storage media available are things like Environment , where you can do things like getExternalStorageDirectory(), which returns a File, not File[] or anything like that. 但是,关于枚举可用存储介质的数量,我似乎只能找到类似于Environment之类的东西,您可以在其中执行getExternalStorageDirectory()之类的操作,该方法返回一个File,而不是File []或类似的东西。 Is there a safer, generalized way to enumerate all the storage media available? 有没有一种更安全,通用的方法来枚举所有可用的存储介质? Do you just have to navigate to /mnt/ and get a listing there to see all the mounted volumes? 您是否只需要导航到/ mnt /并在那里获得清单以查看所有已安装的卷?

Is there a safer, generalized way to enumerate all the storage media available? 有没有一种更安全,通用的方法来枚举所有可用的存储介质?

From the SDK standpoint, there is internal storage ( getFilesDir() ) and there is external storage ( Environment.getExternalStorageDirectory() ). 从SDK的角度来看,存在内部存储( getFilesDir() )和外部存储( Environment.getExternalStorageDirectory() )。 On Android 1.x/2.x, those will be separate partitions; 在Android 1.x / 2.x上,这些将是单独的分区; on Android 3.0+, they will be a single partition. 在Android 3.0+上,它们将是一个分区。

By definition, doing anything beyond what the SDK offers will be unsafe. 根据定义,做任何超出SDK提供的范围的事情都是不安全的。 There are no guarantees about partition names, what their roles are, whether you can read from them, whether you can write to them, etc. Even if you were to build a database of all the possibilities (model, OS version, partitions, and their status), that database would be perpetually out of date vis a vis new devices and OS versions. 无法保证分区名称,它们的作用,是否可以读取它们,是否可以写入它们等等。即使您要建立一个数据库,包括所有可能性(型号,操作系统版本,分区和它们的状态), 相对于新设备和OS版本,该数据库将永远过时。

You may be able to get access to media files on other partitions by means of the MediaStore. 可能可以通过MediaStore来访问其他分区上的媒体文件。 For example, some device manufacturers who offer an SD card in addition to on-board external storage index the SD card's files, so any media files contained on the SD card show up in the MediaStore. 例如,某些设备制造商除了提供板载外部存储设备外还提供SD卡,还会为SD卡的文件编制索引,因此SD卡中包含的所有媒体文件都会显示在MediaStore中。 This may allow you to consume content on other manufacturer-supplied partitions (eg, the SD card), but AFAIK MediaStore offers no means for you to place new files on such partitions. 这可能使您可以使用其他制造商提供的分区(例如SD卡)上的内容,但是AFAIK MediaStore无法为您提供在此类分区上放置新文件的方法。

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

相关问题 Android内部外部存储 - Android Internal External Storage Android内部和外部存储 - Android Internal and External Storage 在Android中的外部存储和内部存储上存储文件 - Storing file on External Storage and Internal Storage in android 如何在android中找到内部(默认手机存储)和外部存储(可移动SD卡)? - How to find Internal(Default Phone Storage ) and External Storage(Removable sd card) in android? 想要列出内部存储和外部存储上的所有音乐文件,但在 Android 10 上无法完成 - Want to list all music file on internal storage and external storage, but it cannot be done on Android 10 如何使用MediaStore获取存储在android的内部存储和外部存储中的所有音乐文件? - How to get all music files stored in internal storage and external storage in android using MediaStore? 获取内部和外部存储信息-Android - get internal and external storage information- android 在Android中将文件从内部存储复制到外部存储 - Copy file from the internal to the external storage in Android 有没有办法确定Android存储设备是内部还是外部? - Is there a way to determine if Android storage device is internal or external? Android文件存储选项-外部+内部 - Android File Storage Options - External + Internal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM