查找可移动SD卡的位置 [英] Find location of a removable SD card

查看:127
本文介绍了查找可移动SD卡的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有通用的方法来查找外部SD卡的位置?

Is there an universal way to find the location of an external SD card?

请不要与外部存储.

Environment.getExternalStorageState()返回到内部SD安装点的路径,例如"/mnt/sdcard".但是问题是关于外部SD.如何获得"/mnt/sdcard/external_sd"之类的路径(可能因设备而异)?

Environment.getExternalStorageState() returns the path to the internal SD mount point, like "/mnt/sdcard". But the question is about the external SD. How do I get a path like "/mnt/sdcard/external_sd" (it may differ from device to device)?

我想我将以文件系统名称过滤mount命令的输出作为结尾.但是我不确定这种方式是否足够健壮.

I guess I will end with filtering of the output of the mount command by filesystem name. But I'm not sure this way is robust enough.

推荐答案

Environment.getExternalStorageState()返回到内部SD安装点的路径,例如"/mnt/sdcard"

Environment.getExternalStorageState() returns path to internal SD mount point like "/mnt/sdcard"

否,Environment.getExternalStorageDirectory()是指设备制造商认为是外部存储"的任何内容.在某些设备上,这是可移动媒体,例如SD卡.在某些设备上,这是设备上闪存的一部分.在此,外部存储"指的是外部存储".表示至少在Android 1.x和2.x上可以通过安装在主机上的USB大容量存储模式访问的东西".

No, Environment.getExternalStorageDirectory() refers to whatever the device manufacturer considered to be "external storage". On some devices, this is removable media, like an SD card. On some devices, this is a portion of on-device flash. Here, "external storage" means "the stuff accessible via USB Mass Storage mode when mounted on a host machine", at least for Android 1.x and 2.x.

但是问题是关于外部SD.如何获得类似"/mnt/sdcard/external_sd"的路径(可能因设备而异)?

But the question is about external SD. How to get a path like "/mnt/sdcard/external_sd" (it may differ from device to device)?

如上所述,除了外部存储设备外,Android还没有外部SD"的概念.

Android has no concept of "external SD", aside from external storage, as described above.

如果设备制造商选择了外部存储为板载闪存并且还具有SD卡,则您需要与该制造商联系,以确定是否可以使用SD卡(不保证)以及如何使用SD卡.规则是关于使用它的,例如使用它的路径.

If a device manufacturer has elected to have external storage be on-board flash and also has an SD card, you will need to contact that manufacturer to determine whether or not you can use the SD card (not guaranteed) and what the rules are for using it, such as what path to use for it.

更新

最近需要注意的两件事:

Two recent things of note:

首先,在Android 4.4+上,您对可移动媒体(例如,外部SD")没有写访问权限,但getExternalFilesDirs()getExternalCacheDirs()可能会返回该媒体上的任何位置.请参见戴夫·史密斯对此的出色分析,特别是如果您希望降低级详细信息.

First, on Android 4.4+, you do not have write access to removable media (e.g., "external SD"), except for any locations on that media that might be returned by getExternalFilesDirs() and getExternalCacheDirs(). See Dave Smith's excellent analysis of this, particularly if you want the low-level details.

第二,以免有人质疑可移动媒体访问是否是Android SDK的一部分,请参见

Second, lest anyone quibble on whether or not removable media access is otherwise part of the Android SDK, here is Dianne Hackborn's assessment:

...请紧记:直到Android 4.4之前,官方的Android平台都不支持 all 的SD卡,除了以下两种特殊情况:旧学校的存储布局,其中外部存储为SD卡(今天该平台仍支持该功能),并在Android 3.0中添加了一个小功能,可以扫描其他SD卡并将其添加到媒体提供商,并为应用提供对其文件的只读访问权限(该功能在以下版本中仍受支持)今天的平台).

...keep in mind: until Android 4.4, the official Android platform has not supported SD cards at all except for two special cases: the old school storage layout where external storage is an SD card (which is still supported by the platform today), and a small feature added to Android 3.0 where it would scan additional SD cards and add them to the media provider and give apps read-only access to their files (which is also still supported in the platform today).

Android 4.4是该平台的第一个版本,实际上已允许应用程序使用SD卡进行存储.在此之前,对它们的任何访问都是通过私有的,不受支持的API进行的.我们现在在平台中拥有一个非常丰富的API,该API允许应用程序以受支持的方式以比以前更好的方式使用SD卡:它们可以免费使用其特定于应用程序的存储区域,而无需任何操作的应用程序权限,并且只要文件通过文件选择器就可以访问SD卡上的任何其他文件,而且无需任何特殊权限即可.

Android 4.4 is the first release of the platform that has actually allowed applications to use SD cards for storage. Any access to them prior to that was through private, unsupported APIs. We now have a quite rich API in the platform that allows applications to make use of SD cards in a supported way, in better ways than they have been able to before: they can make free use of their app-specific storage area without requiring any permissions in the app, and can access any other files on the SD card as long as they go through the file picker, again without needing any special permissions.

这篇关于查找可移动SD卡的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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