推荐安卓开发神器(里面有各种UI特效和android代码库实例)

import java.io.File;import android.os.Environment;import android.os.StatFs;public class MemoryStatus {static final int ERROR = -1;static public boolean externalMemoryAvailable() {    return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);}static public long getAvailableInternalMemorySize() {File path = Environment.getDataDirectory();StatFs stat = new StatFs(path.getPath());long blockSize = stat.getBlockSize();long availableBlocks = stat.getAvailableBlocks();return availableBlocks * blockSize;}static public long getTotalInternalMemorySize() {File path = Environment.getDataDirectory();StatFs stat = new StatFs(path.getPath());long blockSize = stat.getBlockSize();long totalBlocks = stat.getBlockCount();return totalBlocks * blockSize;}static public long getAvailableExternalMemorySize() {if(externalMemoryAvailable()) {File path = Environment.getExternalStorageDirectory();StatFs stat = new StatFs(path.getPath());long blockSize = stat.getBlockSize();long availableBlocks = stat.getAvailableBlocks();return availableBlocks * blockSize;} else {return ERROR;}}static public long getTotalExternalMemorySize() {if(externalMemoryAvailable()) {File path = Environment.getExternalStorageDirectory();StatFs stat = new StatFs(path.getPath());long blockSize = stat.getBlockSize();long totalBlocks = stat.getBlockCount();return totalBlocks * blockSize;} else {return ERROR;}}static public String formatSize(long size) {String suffix = null;if (size >= 1024) {suffix = "KiB";size /= 1024;if (size >= 1024) {suffix = "MiB";size /= 1024;}}StringBuilder resultBuffer = new StringBuilder(Long.toString(size));int commaOffset = resultBuffer.length() - 3;while (commaOffset > 0) {resultBuffer.insert(commaOffset, ',');commaOffset -= 3;}if (suffix != null)resultBuffer.append(suffix);return resultBuffer.toString();}}

更多相关文章

  1. android 用ExpandableListView实现的文件目录树框架
  2. android实现状态栏添加图标的函数实例
  3. Android实现Flip翻转动画效果
  4. Android:intent用法实例
  5. Android应用程序组件Content Provider应用实例(4)
  6. Android中JSON解析细解及实例
  7. Android中js和原生交互的示例代码
  8. Android(安卓)Activity界面切换添加动画特效
  9. Android中结合OrmLite for android组件对SQLite的CRUD(增删改查)

随机推荐

  1. 下拉列表
  2. Android(安卓)ContextThemeWrapper canno
  3. Android自定义底部显示对话框
  4. Android(安卓)根据源码详细讲解Handler
  5. android中fragment的显示和隐藏
  6. 给android添加系统属性
  7. Android之RxPermissions用kotlin写没反应
  8. Android字体设置
  9. 编译代码报出Android(安卓)library proje
  10. android google map 实现拉框功能