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;//可用大小

更多相关文章

  1. Delphi XE5 android 获取网络状态
  2. Android(安卓)获取AndroidManifest.xml 中 meta-data 的值
  3. 获取Android系统程序信息
  4. Android如何从服务器获取图片
  5. [Android]获取网络连接状态
  6. Android(安卓)之 SeekBar用法介绍
  7. Android(安卓)获取设备宽高分辨率
  8. Android中获取和设置手机的壁纸
  9. Android获取手机的型号和系统版本

随机推荐

  1. Android图片压缩及内存缓存
  2. Android开发小技巧
  3. Android之ListActivity(一):布局与数据绑定
  4. 教你用电脑从 Google Play 下载 Android(
  5. 关于Android(安卓)Force Close 出现的原
  6. Android Binder 机制详解
  7. Android 开发中常用到的设计模式
  8. android竖向进度条简单实现
  9. Android超精准计步器开发-Dylan计步
  10. (收集)ListView中常用属性