Getting All the Total and Available Space on Android

How to find the amount of free storage (disk space) left on Android?

Try StatFs.getAvailableBlocks. You'll need to convert the block count to KB with getBlockSize.

How to get exact capacity from storage

When I use my code below it shows me a total capacity of 24,4GB.

That is the amount of space on the partition that contains Environment.getExternalStorageDirectory(). There will be other partitions on the device, for which you will not have access.

How to get the exact 32GB total capacity of my device?

There is no means of doing that, except perhaps on a rooted device.

Get free space on internal memory

this post might fit well to your question.

also check this thread. there is so much info here on SO.

googled a bit and here is the solution (found at android git)

File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return Formatter.formatFileSize(this, availableBlocks * blockSize);

Android get free size of internal/external memory

This is the way I did it :

StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable;
if (android.os.Build.VERSION.SDK_INT >=
android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
bytesAvailable = stat.getBlockSizeLong() * stat.getAvailableBlocksLong();
}
else {
bytesAvailable = (long)stat.getBlockSize() * (long)stat.getAvailableBlocks();
}
long megAvailable = bytesAvailable / (1024 * 1024);
Log.e("","Available MB : "+megAvailable);

How can I check available space on an Android device? On an SD card?

Try this code:

StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());

long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount();
long megAvailable = bytesAvailable / 1048576;

System.out.println("Megs: " + megAvailable);

Explanation

getBlockCount() - return size of SD card;

getAvailableBlocks() - return the number of blocks that are still accessible to normal programs (thanks Joe)



Related Topics



Leave a reply



Submit