在以前我们都是这样获取的
//Android API18之前:fs.getAvailableBlocks()*fs.getBlockSize()
目前:
/** 得到系统可用内存 **/
@SuppressLint("NewApi")
private String getMemFree(){
StatFs fs = new StatFs(Environment.getDataDirectory().getPath());
return Formatter.formatFileSize(this, (fs.getAvailableBytes()));
}
/** 得到SD可用内存 **/
@SuppressLint("NewApi")
private String getSdFree(){
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
StatFs fs = new StatFs(Environment.getExternalStorageDirectory().getPath());
//Android API18之前:fs.getAvailableBlocks()*fs.getBlockSize()
return Formatter.formatFileSize(this, (fs.getAvailableBytes()));
}
return "未装载";
}
终于解决问题了,嘎嘎