Android-----常用的
1 /**
2 * @return return true when the phone's SD card is available; Otherwise return false.
3 */
4 public static boolean hasSDCard() {
5 return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
6 }
7
8 /**
9 * @return return true when the phone's SD card is available and has enough space; Otherwise return false.
10 */
11 public static boolean hasSpace() {
12 if (!hasSDCard()) {
13 return false;
14 }
15 File path = Environment.getExternalStorageDirectory();
16 StatFs statFs = new StatFs(path.getPath());
17
18 int blockSize = statFs.getBlockSize();
19 long availableBlock = statFs.getAvailableBlocks();
20 long spareSize = blockSize * availableBlock;
21
22 return spareSize >= Constants.SDCARD_MIN_SPARE_SIZE;
23 }
2 * @return return true when the phone's SD card is available; Otherwise return false.
3 */
4 public static boolean hasSDCard() {
5 return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
6 }
7
8 /**
9 * @return return true when the phone's SD card is available and has enough space; Otherwise return false.
10 */
11 public static boolean hasSpace() {
12 if (!hasSDCard()) {
13 return false;
14 }
15 File path = Environment.getExternalStorageDirectory();
16 StatFs statFs = new StatFs(path.getPath());
17
18 int blockSize = statFs.getBlockSize();
19 long availableBlock = statFs.getAvailableBlocks();
20 long spareSize = blockSize * availableBlock;
21
22 return spareSize >= Constants.SDCARD_MIN_SPARE_SIZE;
23 }