【文件属性】:
文件名称:获取手机存储空间
文件大小:1.53MB
文件格式:ZIP
更新时间:2017-09-29 07:18:10
android sd
获取手机存储空间值
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);
}
【文件预览】:
TestGetMenoryLeftSize
----.project(857B)
----project.properties(563B)
----src()
--------com()
----AndroidManifest.xml(892B)
----res()
--------drawable-ldpi()
--------drawable-hdpi()
--------values-v11()
--------menu()
--------drawable-mdpi()
--------layout()
--------values-sw600dp()
--------drawable-xxhdpi()
--------drawable-xhdpi()
--------values()
--------values-sw720dp-land()
--------values-v14()
----.settings()
--------org.eclipse.jdt.core.prefs(177B)
----assets()
----gen()
--------com()
----libs()
--------android-support-v4.jar(543KB)
----.classpath(475B)
----proguard-project.txt(781B)
----ic_launcher-web.png(50KB)
----bin()
--------resources.ap_(40KB)
--------classes()
--------AndroidManifest.xml(892B)
--------dexedLibs()
--------TestGetMenoryLeftSize.apk(251KB)
--------jarlist.cache(120B)
--------res()
--------classes.dex(609KB)