-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdevicestore.java
More file actions
47 lines (38 loc) · 1.23 KB
/
devicestore.java
File metadata and controls
47 lines (38 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package org.askquickly.utils;
// import B4A*
import android.os.Environment;
import android.os.StatFs;
public class DiskUtils {
private static final long MEGA_BYTE = 1048576;
public static int totalSpace(boolean external)
{
StatFs statFs = getStats(external);
long total = (((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize())) / MEGA_BYTE;
return (int) total;
}
public static int freeSpace(boolean external)
{
StatFs statFs = getStats(external);
long availableBlocks = statFs.getAvailableBlocks();
long blockSize = statFs.getBlockSize();
long freeBytes = availableBlocks * blockSize;
return (int) (freeBytes / MEGA_BYTE);
}
public static int busySpace(boolean external)
{
StatFs statFs = getStats(external);
long total = (statFs.getBlockCount() * statFs.getBlockSize());
long free = (statFs.getAvailableBlocks() * statFs.getBlockSize());
return (int) ((total - free) / MEGA_BYTE);
}
private static StatFs getStats(boolean external){
String path;
if (external){
path = Environment.getExternalStorageDirectory().getAbsolutePath();
}
else{
path = Environment.getRootDirectory().getAbsolutePath();
}
return new StatFs(path);
}
}