如何确定Android设备有多少张SD卡
我发现使用环境对象来确定SD卡并不可靠。实际上它可以工作,但是有时会显示没有 SD 卡,所以我只使用直接挂载为 /sdcard 并且它可以工作。现在我意识到一个设备可能有多个SD卡。我的设备将其报告为 external-sdcard,因此我可以通过 /external-sdcard 或 /sdcard/external-sdcard 访问此卡。现在的问题是,如何确定特定安装座的类型?我可以遍历目录,但 File 对象没有任何属性告诉我我是 SD 卡。我记得常规 Java 提供了 FileSystem 对象,我可以使用它来检查特定文件,并且该对象可以告诉我 File 对象是简单文件,还是驱动器,或者是外部驱动器。 Android 上有类似的东西吗?
I found that using Environment object isn't reliable;e to determinate SD card. Actually it works, however sometimes tells like as no SD card, so I use just direct mount as /sdcard and it works. Now I realized that a device may have several SD cards. My device report it as external-sdcard, so I can access this card as /external-sdcard or /sdcard/external-sdcard. Now question, how to figure out type of a particular mount? I can traverse directory, but File object doesn't have any attribute telling me I am SD card. I remember regular Java provides FileSystem objects which I can use to inspect particular files and this object can tell me if a File object is simple file, or it is drive, or it is external drive. Is something like that available for Android?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK,目前记录的 API 仅支持一张 SD 卡(实际上是外部存储)。
您可以使用
Environment.getExternalStorageDirectory()
获取目录,并使用Enviroment.getExternalStorageState()
检查它是否已挂载。除此之外的任何东西似乎(目前)不受支持。
记住这一点,您可以解析 /proc/mounts 来找出哪些文件系统安装在哪里。
AFAIK, the currently documented API only supports one SD card (actually external storage).
You can use
Environment.getExternalStorageDirectory()
to get the directory, andEnviroment.getExternalStorageState()
to check if it is mounted.Anything besides that seems to be (currently) unsupported.
Bearing that in mind, you could parse
/proc/mounts
to find out what file systems are mounted where.