Android的获得所有可用的存储设备 [英] Android get all available storage devices
问题描述
有没有什么功能/方法,它允许检测各种不同的存储到您的手机与他们的名字。我的意思是,检测所有内部/外部存储如果您的设备上的多个。以及如何检测是否有可用SD卡或不?
Is there any function/method which allow to detect all kind of different storage to your phone with their names. I mean to detect all internal/external storage if there is more than one available on your device. And how to detect if there is available SD Card or not?
在此先感谢!
推荐答案
我不知道其他类型的存储设备,我只知道内部存储和外部存储的Android设备。
I don't know about other types of storage device, I only know Internal Storage and External Storage device for android.
现在可用的检查外部存储类似,
public static boolean isSdPresent() {
return android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED);
}
return type boolean(true->available,false->NA).
和对于内部存储,(内部存储始终保持(present),所以没有必要检查)刚刚获得像,
And for Internal storage, (Internal storage is always remain (present) so no need to check it) just get like,
File path = Environment.getDataDirectory();
现在,在这两种情况下,检查可用内存和使用的内存,
Now, in both case to check available free memory and usage memory,
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return Formatter.formatFileSize(this, availableBlocks * blockSize);
这篇关于Android的获得所有可用的存储设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!