- 博客(0)
- 资源 (7)
- 收藏
- 关注
获取手机存储空间
获取手机存储空间值
private String getInternalMemoryPath() {
return Environment.getDataDirectory().getPath();
}
/**
*
* @return 内置sd卡路径
*/
private String getExternalMemoryPath() {
// return Environment.getExternalStorageDirectory().getPath();
return "/mnt/sdcard";
}
/**
*
* @return 外置sd卡路径
*/
private String getSDCard2MemoryPath() {
return "/mnt/sdcard1";
}
/**
*
* @param path
* 文件路径
* @return 文件路径的StatFs对象
* @throws Exception
* 路径为空或非法异常抛出
*/
private StatFs getStatFs(String path) {
try {
return new StatFs(path);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
*
* @param stat
* 文件StatFs对象
* @return 剩余存储空间的MB数
*
*/
private float calculateSizeInMB(StatFs stat) {
if (stat != null)
return stat.getAvailableBlocks()
* (stat.getBlockSize() / (1024f * 1024f));
return 0.0f;
}
/**
*
* @return ROM剩余存储空间的MB数
*/
private float getAvailableInternalMemorySize() {
String path = getInternalMemoryPath();// 获取数据目录
StatFs stat = getStatFs(path);
return calculateSizeInMB(stat);
}
/**
*
* @return 内置SDCard剩余存储空间MB数
*/
private float getAvailableExternalMemorySize() {
String path = getExternalMemoryPath();// 获取数据目录
StatFs stat = getStatFs(path);
return calculateSizeInMB(stat);
}
/**
*
* @return 外置SDCard剩余存储空间MB数
*/
private float getAvailableSDCard2MemorySize() {
// String status = Environment.getExternalStorageState();
// if (status.equals(Environment.MEDIA_MOUNTED)) {
// }
String path = getSDCard2MemoryPath(); // 获取数据目录
StatFs stat = getStatFs(path);
return calculateSizeInMB(stat);
}
2014-09-09
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人