Android get all available storage devices

浪尽此生 提交于 2019-12-22 10:58:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!