标签:
查找“可用空间”得到
<string name="memory_available" msgid="418542433817289474">"可用空间"</string>
查找"memory_available",得到
<Preference android:key="memory_sd_avail"
style="?android:attr/preferenceInformationStyle"
android:title="@string/memory_available"
android:summary="00"/>
查找"memorysdavail",得到
//这个字符串就是sd卡剩余容量
formatSize(availableBlocks * blockSize) + readOnly
//这两个参数相乘,得到sd卡以字节为单位的剩余容量
availableBlocks * blockSize
存储设备会被分为若干个区块,每个区块有固定的大小
示例代码
File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize; long totalBlocks; long availableBlocks; //获取当前系统版本的等级 if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2){ blockSize = stat.getBlockSizeLong(); totalBlocks = stat.getBlockCountLong(); availableBlocks = stat.getAvailableBlocksLong(); } else{ blockSize = stat.getBlockSize(); totalBlocks = stat.getBlockCount(); availableBlocks = stat.getAvailableBlocks(); } TextView tv = (TextView) findViewById(R.id.tv); tv.setText(formatSize(availableBlocks * blockSize)); } private String formatSize(long size) { return Formatter.formatFileSize(this, size); }
标签:
原文地址:http://www.cnblogs.com/zxtian1987/p/4792295.html