其他分享
首页 > 其他分享> > android – 查找可移动SD卡的位置

android – 查找可移动SD卡的位置

作者:互联网

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

请不要与External Storage混淆.Environment.getExternalStorageState()返回内部SD挂载点的路径,如“/ mnt / sdcard”.但问题是关于外部SD.如何获得像“/ mnt / sdcard / external_sd”这样的路径(它可能因设备而异)?

我想我将以文件系统名称过滤mount命令结束.但我不确定这种方式是否足够强大.

解决方法:

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

不,Environment.getExternalStorageDirectory()是指设备制造商认为是“外部存储”的任何内容.在某些设备上,这是可移动媒体,如SD卡.在某些设备上,这是设备上闪存的一部分.这里,“外部存储”是指“安装在主机上时通过USB大容量存储模式可访问的内容”,至少对于Android 1.x和2.x.

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”的概念,如上所述.

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

UPDATE

最近有两点需要注意:

首先,在Android 4.4上,除了可能由getExternalFilesDirs()和getExternalCacheDirs()返回的媒体上的任何位置之外,您没有对可移动媒体的写访问权(例如,“外部SD”).请参阅Dave Smith’s excellent analysis,特别是如果您想要低级别的详细信息.

其次,以免任何人狡辩是否可移动媒体访问是否是Android SDK的一部分,这里是Dianne Hackborn’s assessment

…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 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.

标签:android,sd-card,external
来源: https://codeday.me/bug/20190911/1802756.html