Reputation: 33
When I use StatFs to get the total internal storage of my Galaxy S7, it's not returning the true amount of bytes:
statFs = new StatFs(Environment.getDataDirectory().getAbsolutePath());
final long blockSize = statFs.getBlockSizeLong();
final long totalBlocks = statFs.getBlockCountLong();
final long freeBlocks = statFs.getAvailableBlocksLong();
final long totalBytes = blockSize * totalBlocks;
final long freeBytes = blockSize * freeBlocks;
On my Galaxy S7 (32GB), it shows this: 26426515456 bytes, which corresponds only to 24.61GB?
Upvotes: 3
Views: 436
Reputation: 1007584
it's not returning the true amount of bytes ?
By definition, it is returning "the true amount of bytes". What it is not returning is a number that you expect.
StatFs
reports statistics about a filesystem on a particular partition, whatever partition the file that you happen to pass is resides upon. A 32GB Android device will not have a single 32GB partition. That 32GB will be divided into several partitions. While you will be able to get statistics about the partition that holds internal storage and external storage, separate partitions will hold other things, such as the recovery partition used for factory resets.
You can try running adb shell df
to see some of the partitions on your device (this works on a Pixel running Android 7.1, but I do not know how common the df
command is).
Upvotes: 3
Reputation: 371
Probably because this method doesn't visualize the memory alocated for system and important files but just the usable memory.
Upvotes: 1