How to Check available space on android device ? on 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);
Update:
getBlockCount()
- return size of SD card;
getAvailableBlocks()
- return the number of blocks that are still accessible to normal programs (thanks Joe)
How read and display available space in android both sd card and internal memory?
Try this code:
public static long remainingLocalStorage()
{
StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
stat.restat(Environment.getDataDirectory().getPath());
long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getAvailableBlocks();
return bytesAvailable;
}
Correct way to check disk space available for Android app?
Well if you have the path I believe your answer can be found inside How to find the amount of free storage (disk space) left on Android?, check the code samples there.
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 check availability of space on external storage?
Use StatFs
and pass the path of the external storage directory to the constructor and you can call functions such as getAvailableBlocks()
and getBlockSize()
on the StatFs
object.
How to get available/free sdcard space in android with adb command
Use df
, as with any Linux distro. Not all Android devices may have it, but it usually seems to be available.
How to get actual size of mounted SD card in Android?
Yes, there is a way.
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long sdAvailSize = (long)stat.getAvailableBlocks()
* (long)stat.getBlockSize();
//One binary gigabyte equals 1,073,741,824 bytes.
long gigaAvailable = sdAvailSize / 1073741824;
Got that from here: How can I check how much free space an SD card mounted on an Android device has?
Concerning your question about getting total size look here: Getting all the total and available space on Android
Edit:
Marcelo Filho has pointed out that this method is deprecated in API 18 (KitKat).
Google suggests to use getAvailableBlocksLong ()
and getBlockCountLong ()
instead. Both methods will return a long value and not a double.
Hint:
Kikiwa has pointed out that the datatype long should be used with these -now deprecated - methods, otherwise you may get negative values if the filesize is too large.
Related Topics
What Is the Use of System.In.Read()
Configuring Log4J Loggers Programmatically
Can CSS in Javafx Be Used for Animations
How to Get an Android User's Email Address
Android Archive Library (Aar) VS Standard Jar
How to Use the Java 8 Stream API on Android API < 24
Android: How to Handle Button Click
How to Navigate from One Screen to Another Screen
Flutter Apps Are Too Big in Size
How Big Is an Object Reference in Java and Precisely What Information Does It Contain
Preventing System.Exit() from API
How to Fix Google Cloud Messaging Registration Error: Service_Not_Available
Show Only Two Digit After Decimal