我的应用程序正在将文件保存在SD卡上,但在保存文件之前,我需要检查是否有空闲内存.我需要检查SD卡上有多少可用内存.
就像是:
if(MemoryCard.getFreeMemory()>20Mb) { saveFiles(); } else { Toast.makeText(this,"Not enough memory",100).show(); }
解决方法
来自:
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;