Android获取sdcard信息
16lz
2022-03-16
1>实例代码:
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {File path = Environment.getExternalStorageDirectory();StatFs statFs = new StatFs(path.getPath());long blockSize = statFs.getBlockSize();long totalBlocks = statFs.getBlockCount();long availableBlocks = statFs.getAvailableBlocks();String[] total = fileSize(totalBlocks * blockSize);String[] available = fileSize(availableBlocks * blockSize);int ss = (int) (((totalBlocks-availableBlocks) / (totalBlocks * 1.0)) * myProgressBar.getMax());myProgressBar.setProgress(ss);String text = available[0] + available[1] + "可用 \t总" + total[0] + total[1];myTextView.setText(text);} else if (Environment.getExternalStorageState().equals(Environment.MEDIA_REMOVED)) {String text = "SD CARD 已删除";myTextView.setText(text);}
2>获取sdcard状态
Environment.getExternalStorageState()//获得扩展存储设备状态MEDIA_BAD_REMOVAL//安全卸载前强制拔除MEDIA_CHECKING//正在扫描MEDIA_MOUNTED//已挂载MEDIA_MOUNTED_READ_ONLY//只读MEDIA_NOFS//sdcar是空的,或文件系统不支持MEDIA_REMOVED//已移除MEDIA_SHARED//未挂载,并以USB模式和计算机连接MEDIA_UNMOUNTABLE//有sdcard,但无法挂载MEDIA_UNMOUNTED//有sdcard,但未挂载
String | MEDIA_BAD_REMOVAL | getExternalStorageState() returns MEDIA_BAD_REMOVAL if the media was removed before it was unmounted. |
String | MEDIA_CHECKING | getExternalStorageState() returns MEDIA_CHECKING if the media is present and being disk-checked |
String | MEDIA_MOUNTED | getExternalStorageState() returns MEDIA_MOUNTED if the media is present and mounted at its mount point with read/write access. |
String | MEDIA_MOUNTED_READ_ONLY | getExternalStorageState() returns MEDIA_MOUNTED_READ_ONLY if the media is present and mounted at its mount point with read only access. |
String | MEDIA_NOFS | getExternalStorageState() returns MEDIA_NOFS if the media is present but is blank or is using an unsupported filesystem |
String | MEDIA_REMOVED | getExternalStorageState() returns MEDIA_REMOVED if the media is not present. |
String | MEDIA_SHARED | getExternalStorageState() returns MEDIA_SHARED if the media is present not mounted, and shared via USB mass storage. |
String | MEDIA_UNMOUNTABLE | getExternalStorageState() returns MEDIA_UNMOUNTABLE if the media is present but cannot be mounted. |
String | MEDIA_UNMOUNTED | getExternalStorageState() returns MEDIA_UNMOUNTED if the media is present but not mounted. |
3>获取sdcard状态
File path = Environment.getExternalStorageDirectory();//获得sdcard路径StatFs statFs = new StatFs(path.getPath());long blockSize = statFs.getBlockSize();//获取块大小long totalBlocks = statFs.getBlockCount();//获取总块数long availableBlocks = statFs.getAvailableBlocks();//获取可用块数long totalSize = totalBlocks*blockSize;//总大小long availableSize = availableBlocks*blockSize;//可用大小
更多相关文章
- Delphi XE5 android 获取网络状态
- Android(安卓)获取AndroidManifest.xml 中 meta-data 的值
- 获取Android系统程序信息
- Android如何从服务器获取图片
- [Android]获取网络连接状态
- Android(安卓)之 SeekBar用法介绍
- Android(安卓)获取设备宽高分辨率
- Android中获取和设置手机的壁纸
- Android获取手机的型号和系统版本