我怎么能检查多少可用空间SD卡安装在Android设备了? [英] How can I check how much free space an SD card mounted on an Android device has?
本文介绍了我怎么能检查多少可用空间SD卡安装在Android设备了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何以编程方式检查多少可用空间SD卡安装在Android设备上了?
How can I programmatically check how much free space an SD card mounted on an Android device has?
推荐答案
要获得外部SD卡的用自由空间来显示一些它同意菜单 - >设置 - > SD卡和手机存储的号码,使用以下code:
To get the external SD card's available "free" space to show a number which agrees with the Menu->Settings->SD card and phone storage's number, use the following code:
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
double sdAvailSize = (double)stat.getAvailableBlocks()
* (double)stat.getBlockSize();
//One binary gigabyte equals 1,073,741,824 bytes.
double gigaAvailable = sdAvailSize / 1073741824;
相关文章:<一个href="http://developer.android.com/reference/android/os/StatFs.html">http://developer.android.com/reference/android/os/StatFs.html
这篇关于我怎么能检查多少可用空间SD卡安装在Android设备了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文