问题
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?
Thanks in advance!
回答1:
I don't know about other types of storage device, I only know Internal Storage and External Storage device for android.
Now for check available external storage something like,
public static boolean isSdPresent() {
return android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED);
}
return type boolean(true->available,false->NA).
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);
回答2:
Try this one..
public static boolean isSdCardPresent() {
return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
}
来源:https://stackoverflow.com/questions/8133601/android-get-all-available-storage-devices