检查SD卡为present,布尔值始终为true
在我的闪屏,我要检查,如果手机有一个SD卡。布尔语句是下面:
In my splash screen, I want to check if the phone has a SDCard. The Boolean statement is beneath:
Boolean isSDPresent = android.os.Environment.getExternalStorageState()
.equals(android.os.Environment.MEDIA_MOUNTED );
所以,如果我在我的手机上的插槽SD卡,这个布尔将返回true,到目前为止,一切顺利。当我去了卸载SD卡,从设置菜单,并删除SD卡,然后杀死的应用程序,然后重新启动它,布尔也将是如此。
So, if I have the SDCard in the slot on my phone, this boolean will return true, so far so good. When I go to the "Unmount SDCard" from the settings menu, and removes the SDCard, then kill the app and launching it again, the boolean will also be true..
如果我启动天文文件管理器
卸载和删除的SD卡后,我仍然可以访问到/ mnt / SD卡
路径,为什么?
And if I launches the Astro File Manager
after unmounting and removing the sdcard, I can still access the /mnt/sdcard
path, why?
我如何管理做到这一点?
How can I manage to accomplish this?
在此先感谢!
修改
测试与下面的code:
Testing with the following code:
File path = Environment.getExternalStorageDirectory();
String pathS = path.getPath();
在SD卡在插槽中,路径
包含 MNT / SD卡
,但是当我删除SD卡在路径
还是到/ mnt / SD卡
...
When the SDCard is in the slot, the pathS
contains mnt/sdcard
, but when I removes the SDCard the pathS
is still /mnt/sdcard
...
我发现手机,如三星银河手机,有到/ mnt / SD卡
点到内存,而不是外部的SD卡作为预期。
I've found that phones, like the Galaxy phones from Samsung, have /mnt/sdcard
point to internal memory and not the external SD card as expected.
您可以知道,如果路径由Environment.getExternalStorageDirectory()实际上就是外置SD卡调用Environment.isExternalStorageRemovable()
You can know if the path returned by Environment.getExternalStorageDirectory() is actually the external SD card with a call to Environment.isExternalStorageRemovable()
只是想从文档的getExternalStorageDirectory()这个重要的注意事项补充:
Just wanted to add from the docs for getExternalStorageDirectory() this important note:
请注意:千万不要被这个词迷惑外部在这里。此目录 可以更好地被认为是媒体/共享存储。它是一个文件系统, 可以容纳比较大量的数据和被跨越共享 所有的应用程序(不强制许可)。传统上,这是 SD卡,但它也可以被实现为内置存储在一个 装置,其从被保护的内部存储不同,并且可以是 作为安装在计算机上的文件系统。
Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.