【工具类】Android判断SD卡状态
定义一个工具类
public class Util { public static void getSD(Activity activity) { String sdCardState = Environment.getExternalStorageState(); if (sdCardState.equals(Environment.MEDIA_REMOVED)) { Toast.makeText(activity, "请插入存储卡", 1).show(); return; } else if (sdCardState.equals(Environment.MEDIA_CHECKING)) { Toast.makeText(activity, "正在检测存储卡,请稍候再试", 1).show(); return; } if(!sdCardState.equals(Environment.MEDIA_MOUNTED)) { Toast.makeText(activity, "当前存储卡不可用", 1).show(); return; } } }
在Activity中调用
Util.getSD(MainActivity.this);