Android的 - 找到所有内部和外部存储 [英] Android - Find all internal and external storage

查看:139
本文介绍了Android的 - 找到所有内部和外部存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我已经注意到,从设备到设备,也有内部与外部多种不同的配置。在我的Evo但只是内部存储和外部SD卡,但是从同年Droid难以置信,有内部存储,内置SD卡(8GB〜)和外部SD卡(1GB默认)。 presumably还有其它配置,而且会有更多的即将到来。

不过,所有我似乎可以找到有关列举可用存储介质的数量之类的环境,在那里你可以做这样的事情getExternalStorageDirectory(),它返回一个文件,而不是文件[]或类似的东西。有没有枚举所有存储介质更安全,通用的方法可用?你只需要浏览到/ mnt /和获得的列表那里看到所有已安装的卷?


解决方案

  

有枚举所有存储介质更安全,更广义的方式提供?


从SDK的角度来看,有内部存储( getFilesDir()),并有外部存储( Environment.getExternalStorageDirectory())。在Android 1.x中/ 2.x中,这些将是单独的分区;在Android 3.0+,他们将一个分区。

根据定义,做任何事情超出了SDK提供了将是不安全的。没有关于分区名称的担保,有什么自己的角色,是否可以读取它们,您是否可以给他们写信,等等。即使你建立的一切准备(型号,操作系统版本,分区的数据库,他们的身份),该数据库将永远过时的相一相的新设备和操作系统版本。

您的可能的是能够通过MediaStore的手段来获得访问其他分区上的媒体文件。例如,包含在SD卡上的某些设备制造商谁,除了板载外置存储索引SD卡中的文件提供了一个SD卡,所以任何媒体文件在MediaStore露面。这可能让你在消费其他制造商提供的分区的内容(例如,SD卡),但据我所知MediaStore提供绝不让你放在这些分区的新文件。

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). 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. 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?

解决方案

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()). On Android 1.x/2.x, those will be separate partitions; on Android 3.0+, they will be a single partition.

By definition, doing anything beyond what the SDK offers will be unsafe. 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.

You may be able to get access to media files on other partitions by means of the 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. This may allow you to consume content on other manufacturer-supplied partitions (e.g., the SD card), but AFAIK MediaStore offers no means for you to place new files on such partitions.

这篇关于Android的 - 找到所有内部和外部存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆