Android 安卓系统中的可用磁盘空间是什么?
一个代码/简单函数,将返回主android设备中可用和使用的磁盘空间 生成df命令并对其进行解析是最好的方法吗?还可以使用哪些其他方法Android 安卓系统中的可用磁盘空间是什么?,android,Android,一个代码/简单函数,将返回主android设备中可用和使用的磁盘空间 生成df命令并对其进行解析是最好的方法吗?还可以使用哪些其他方法 事先非常感谢我设法修好了一门好课 // PHONE STORAGE public static long phone_storage_free(){ File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long free
事先非常感谢我设法修好了一门好课
// PHONE STORAGE
public static long phone_storage_free(){
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long free_memory = stat.getAvailableBlocks() * stat.getBlockSize(); //return value is in bytes
return free_memory;
}
public static long phone_storage_used(){
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long free_memory = (stat.getBlockCount() - stat.getAvailableBlocks()) * stat.getBlockSize(); //return value is in bytes
return free_memory;
}
public static long phone_storage_total(){
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long free_memory = stat.getBlockCount() * stat.getBlockSize(); //return value is in bytes
return free_memory;
}
// SD CARD
public static long sd_card_free(){
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long free_memory = stat.getAvailableBlocks() * stat.getBlockSize(); //return value is in bytes
return free_memory;
}
public static long sd_card_used(){
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long free_memory = (stat.getBlockCount() - stat.getAvailableBlocks()) * stat.getBlockSize(); //return value is in bytes
return free_memory;
}
public static long sd_card_total(){
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long free_memory = stat.getBlockCount() * stat.getBlockSize(); //return value is in bytes
return free_memory;
}
我试图使用df命令进行系统调用并解析输出,但可能存在重复。但是他们的API函数是否用于此目的?不推荐使用API>=18的getAvailableBlocks()和getBlockSize()。使用
getAvailableBlocksLong()
和getBlockSizeLong()
代替。如果API>=18,您可以直接调用getAvailableBytes(),而不必考虑块和块大小。