android:查找 SD 卡是否存在
我遇到问题了。我有一个 Galaxy Tab,配有 16GB 内部存储空间和 2GB SD 卡。
当我使用environment.getExternalStorageState时,它返回mounted。但是,当我从 Galaxy Tab 中取出 SD 卡时,它仍然返回已安装状态,因为它将内部存储视为外部存储。有什么方法可以区分实际的 SD 卡和内部存储吗?
谢谢
I am having a problem. I have a galaxy tab that comes with 16gb of internal storage and 2 gb of sd-card card.
when I use environment.getExternalStorageState, it returns mounted. However, when I remove the sd-card from my galaxy tab, it still returns mounted because it considers the internal storage as the external storage. Is there any way in which I can differentiate between the actual SD-Card and the Internal Storage?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
目前似乎没有任何公共 API。您可以通过查看
/proc/mounts
进行检查,但您的代码将取决于设备,因为并非所有设备都在同一位置安装辅助外部存储(SD 卡)。There doesn't seem to be any public API for this currently. You could check by looking at
/proc/mounts
but your code would then be device-dependent, since not all devices mount secondary external storage (SD card) at the same place.如果存在两个存储选项,我认为
/storage/sdcard0/
用于内部 SD 卡,/storage/sdcard1/
用于外部 SD 卡。如果您要检查某个文件是否存在于任何 SD 卡中,您应该检查所有可能的路径。
I think
/storage/sdcard0/
is used for internal sdcard and/storage/sdcard1/
is used for external sd card if there are two storage option present.if you are checking a file is present either in any of sdcard or not you should check all possible paths.
我自己创建了一张支票,并且有效。它检查辅助的、真实的 SD 卡是否存在。
在三星 Galaxy s5 neo、阿尔卡特 one touch 5020x 和 HTC One X 上进行了测试。
该代码应该适用于 KITKAT 设备,因为它使用应用程序默认目录进行检查。
我在主存储上创建了一个默认应用程序路径存储的字符串。
然后将“主要”更改为“辅助”,然后尝试创建一个文件夹并检查是否存在。
代码如下:
I've created a check of my own, and it works. It checks if secondary, real SD card is present.
Tested it on Samsung Galaxy s5 neo, Alcatel one touch 5020x, and on HTC One X.
The code should work on KITKAT devices since it uses the app default dir to check.
I create a String of default app path storage on primary storage.
Then change "primary" to "secondary", then try to create a folder and check for existance.
Heres the code:
我尝试这样做
或这个例子会帮助你
I try like this
or this example would help you