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
How to Use Data Binding and Kotlin in Android Studio 3.0.0
Capturing Images with Mediastore.Action_Image_Capture Intent in Android
How to Include a Library Module Dependency in an Android Studio Project
Scoping States in Jetpack Compose
Status Bar Turns White and Does Not Show Content Behind It
How to Implement Pagination in Android Listview
Android Accessibility Service Detect Notification
Delete File from Internal Storage
How to Add .So Files to an Android Library Project Using Gradle 0.7+
Rendering Problems in Android Studio V 1.1/1.2
Set Visibility in Menu Programmatically Android
How to Check If Running on UI Thread in Android
How to Disable Dates Before Today Date in Datepickerdialog Android
Detecting Gps On/Off Switch in Android Phones
Android:Change Button Text and Background Color
How to Get Any Identifier of the Topmost Activity
Sending Pictures to a Web Server
Setsupportactionbar Toolbar Cannot Be Applied to (Android.Widget.Toolbar) Error