Java – programmatically check whether there is enough memory on the SD card
•
Java
My application is saving the file on the SD card, but before saving the file, I need to check whether there is free memory I need to check how much memory is available on the SD card
It's like:
if(MemoryCard.getFreeMemory()>20Mb) { saveFiles(); } else { Toast.makeText(this,"Not enough memory",100).show(); }
Solution
come from: http://groups.google.com/group/android-developers/browse_thread/thread/ecede996463a4058
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); long bytesAvailable = (long)stat.getBlockSize() * (long)stat.getBlockCount(); long megAvailable = bytesAvailable / 1048576;
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码