/*
* 初始化标题数据
* */
private void initTitle() {
TextView tvPhoneMemory = (TextView) findViewById(R.id.tv_phone_memory);
TextView tvSDMemory = (TextView) findViewById(R.id.tv_sd_memory);
// 获得外部存储与手机的根文件夹路径
String path = Environment.getDataDirectory().getAbsolutePath();
String sdPath = Environment.getExternalStorageDirectory().getAbsolutePath();
// 调用自定义函数获得手机的可用空间大小
long getpath = getAvaliableSpace(path);
long getSdPath = getAvaliableSpace(sdPath);
tvPhoneMemory.setText(Formatter.formatFileSize(this,getpath));
tvSDMemory.setText(Formatter.formatFileSize(this,getSdPath));
}
private long getAvaliableSpace(String path) {
// 声明磁盘可用空间大小的类
StatFs statFs = new StatFs(path);
// 总的可用空间= 可用区块数 * 区块大小大小
long count = statFs.getAvailableBlocks();//个数
long size = statFs.getBlockSize();// 每个的大小
return count * size;
}
网友评论