问题描述
这是真的,文件路径外部SD卡在Android设备上总是 存储/ extSdCard?如果没有,有多少变化呢?
我需要为我的应用程序,以测试外部 SD卡可用。
我使用的钛,它有一个方法的的 Titanium.Filesystem.isExternalStorage present()的但它始终返回true,即使外部SD卡未安装。
我觉得它检测到的SD卡在本地存储从而返回true。但我真正想要的是检测物理SD卡是否被安装与否。
我可以做到这一点通过检测文件是否存在/存储/ extSdCard一个人吗?
感谢。
不幸的路径外部存储不总是根据制造商的相同。使用 Environment.getExternalStorageDirectory()
返回你的SD卡,是 MNT / SD卡/
的正常路径。但是对于三星的设备,例如,SD卡路径是根据 MNT / extSdCard /
或在 MNT / external_sd /
因此,为了继续进行一种方法是根据所使用的每个制造商的路径检查外部目录的存在。像这样的东西:
mExternalDirectory = Environment.getExternalStorageDirectory()
.getAbsolutePath();
如果(android.os.Build.DEVICE.contains(三星)
|| android.os.Build.MANUFACTURER.contains(三星)){
文件F =新的文件(Environment.getExternalStorageDirectory()
.getParent()+/ extSdCard+/ myDirectory);
如果(f.exists()&安培;&安培; f.isDirectory()){
mExternalDirectory = Environment.getExternalStorageDirectory()
.getParent()+/ extSdCard;
} 其他 {
F =新的文件(Environment.getExternalStorageDirectory()
.getAbsolutePath()+/ external_sd+/ myDirectory);
如果(f.exists()&安培;&安培; f.isDirectory()){
mExternalDirectory =环境
.getExternalStorageDirectory()。getAbsolutePath()
+/ external_sd;
}
}
}
我没有尝试在code还,但德米特里Lozenko在此回答是多少更有意思的。 他的方法返回制造商的所有已安装的SD卡上的系统正路径,无论
Is it true that the file path to external SDCard on Android devices are always "/storage/extSdCard"? If not, how many variations are there?
I need it for my App to test the availability of external SDCard.
I am using Titanium, it has a method Titanium.Filesystem.isExternalStoragePresent( )but it always return true even external SDCard is not mounted.
I think it detect SDCard at local storage thus return true. But what I really want is detect whether physical SDCard is mounted or not.
Can I do this by detecting the existence of file "/storage/extSdCard" alone?
Thanks.
Sadly the path to the external storage is not always the same according to manufacturer. Using Environment.getExternalStorageDirectory()
will return you the normal path for SD card which is mnt/sdcard/
. But for Samsung devices for example, the SD card path is either under mnt/extSdCard/
or under mnt/external_sd/
.
So one way to proceed would be to check the existence of external directory according to the path used by each manufacturer. With something like this:
mExternalDirectory = Environment.getExternalStorageDirectory()
.getAbsolutePath();
if (android.os.Build.DEVICE.contains("samsung")
|| android.os.Build.MANUFACTURER.contains("samsung")) {
File f = new File(Environment.getExternalStorageDirectory()
.getParent() + "/extSdCard" + "/myDirectory");
if (f.exists() && f.isDirectory()) {
mExternalDirectory = Environment.getExternalStorageDirectory()
.getParent() + "/extSdCard";
} else {
f = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/external_sd" + "/myDirectory");
if (f.exists() && f.isDirectory()) {
mExternalDirectory = Environment
.getExternalStorageDirectory().getAbsolutePath()
+ "/external_sd";
}
}
}
I didn't try the code yet, but the approach of Dmitriy Lozenko in this answer is much more interesting. His method returns the path of all mounted SD cards on sytem regardless of the manufacturer.
这篇关于为Android外部SD卡文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!