Fix free storage space check for all APIs
See https://stackoverflow.com/q/31171838 See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fstatvfs.html
This commit is contained in:
parent
00770fc634
commit
c3c39a7b24
3 changed files with 50 additions and 66 deletions
|
|
@ -40,20 +40,6 @@ public class Utility {
|
|||
UNKNOWN
|
||||
}
|
||||
|
||||
/**
|
||||
* Get amount of free system's memory.
|
||||
* @return free memory (bytes)
|
||||
*/
|
||||
public static long getSystemFreeMemory() {
|
||||
try {
|
||||
final StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
|
||||
return statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong();
|
||||
} catch (final Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static String formatBytes(long bytes) {
|
||||
Locale locale = Locale.getDefault();
|
||||
if (bytes < 1024) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue