I am new in android and have question about Internal and External memory. I use 2 way to determine memory usage. First way is this:
public static String getAvailableInternalMemorySize() {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return formatSize(availableBlocks * blockSize);
}
public static String getTotalInternalMemorySize() {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
return formatSize(totalBlocks * blockSize);
}
public static String getAvailableExternalMemorySize() {
if (externalMemoryAvailable()) {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return formatSize(availableBlocks * blockSize);
} else {
return "ERROR";
}
}
and the second one is:
public long InternalTotalMemory(){
StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
long blockCount = statFs.getBlockCountLong();
long blockSize = statFs.getBlockSizeLong();
long total = blockCount * blockSize;
return total;
}
public long InternalFreeMemory(){
StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
long availableBlock = statFs.getAvailableBlocksLong();
long blockSize = statFs.getBlockSizeLong();
long free = availableBlock * blockSize;
return free;
}
But I don't understand why they show different values. 1) Total internal memory 4 GB Available internal memory 4 GB
2) Total internal memory 991,898 MB Available internal memory 632,266 MB
Where is my mistake or calculation is wrong.