Get Free Space on Internal Memory

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 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.

Checking if the storage is full before writing to internal storage

You have asked several questions, but all you need to do is a simple check to see if there is available storage memory before proceeding with any file write operation.

You can use this utility method to quickly check for free storage space on the device,

 public static long getAvailableInternalMemorySize() {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize, availableBlocks;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
blockSize = stat.getBlockSizeLong();
availableBlocks = stat.getAvailableBlocksLong();
} else {
blockSize = stat.getBlockSize();
availableBlocks = stat.getAvailableBlocks();
}
return availableBlocks * blockSize;
}

As you know you can get the size of your files using the length() method of the files. It will return you the size of each file in bytes.

All you need to do is compare the size of the files you intend to write with the available storage memory. If the size of your files is less than the total storage available, you can go ahead and write your files.

Retrieve free internal memory on an Android device

Try this. following code returns Internal Storage Memory in MB ,

StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
long bytesAvailable = (long)stat.getFreeBlocks() * (long)stat.getBlockSize();
long megAvailable = bytesAvailable / 1048576;

How to monitor android device free space programatically

The contents of getRootDirectory() is unlikely to change, since that partition is read-only.

If you want to monitor free space, you have to choose a file on the partition that matters to you, such as getFilesDir() to find out the free space on internal storage.



Related Topics



Leave a reply



Submit