获取外部SD卡的位置
public static File getExternalStorageDirectory():
获取sd卡的状态
public static String getExternalStorageState():
public static final String MEDIA_REMOVED = "removed";
public static final String MEDIA_UNMOUNTED = "unmounted";
public static final String MEDIA_CHECKING = "checking";
public static final String MEDIA_NOFS = "nofs";
public static final String MEDIA_MOUNTED = "mounted";
public static final String MEDIA_MOUNTED_READ_ONLY = "mounted_ro";
public static final String MEDIA_SHARED = "shared";
public static final String MEDIA_BAD_REMOVAL = "bad_removal";
public static final String MEDIA_UNMOUNTABLE = "unmountable";
获取外部卡的空间大小:
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
file.getFreeSpace();
file.getTotalSpace();
file.getUsableSpace();
但是这里返回的都是字节的大小那么如何转换成M/G呢
Formatter.formatFileSize(context, number)
public static String formatFileSize(Context context, long number)
外部sd中也有对应的不同的目录
public static File getExternalStoragePublicDirectory(String type)
public static String DIRECTORY_MUSIC = "Music";
public static String DIRECTORY_PODCASTS = "Podcasts";
public static String DIRECTORY_RINGTONES = "Ringtones";
public static String DIRECTORY_ALARMS = "Alarms";
public static String DIRECTORY_NOTIFICATIONS = "Notifications";
public static String DIRECTORY_PICTURES = "Pictures";
public static String DIRECTORY_MOVIES = "Movies";
public static String DIRECTORY_DOWNLOADS = "Download";
public static String DIRECTORY_DCIM = "DCIM";