如何检查Android设备上的可用空间?在SD卡上? [英] How to Check available space on android device ? on SD card?
本文介绍了如何检查Android设备上的可用空间?在SD卡上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何查看Android设备上剩余多少MB或GB?我正在使用JAVA和android SDK 2.0.1。
How do I check to see how much MB or GB is left on the android device ? I am using JAVA and android SDK 2.0.1.
是否有任何系统服务会暴露这样的内容?
Is there any system service that would expose something like this ?
推荐答案
尝试此代码:
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount();
long megAvailable = bytesAvailable / 1048576;
System.out.println("Megs :"+megAvailable);
更新:
getBlockCount()
- 返回SD卡的大小;
Update:
getBlockCount()
- return size of SD card;
getAvailableBlocks()
- 返回正常程序仍可访问的块数(感谢Joe)
getAvailableBlocks()
- return the number of blocks that are still accessible to normal programs (thanks Joe)
这篇关于如何检查Android设备上的可用空间?在SD卡上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文