简体   繁体   中英

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). 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 (eg, the SD card), but AFAIK MediaStore offers no means for you to place new files on such partitions.

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