首页 > 系统 > Android > 正文

Android开发实现的获取sdcard大小及内存大小工具类

2019-10-22 18:22:25
字体:
来源:转载
供稿:网友

本文实例讲述了Android开发实现的获取sdcard大小及内存大小工具类。分享给大家供大家参考,具体如下:

public class SDCardUtil {  /**   * SD卡   * @param context   */  public static void getSDCardInfo(Context context){    try {      File path = Environment.getExternalStorageDirectory();      StatFs s = new StatFs(path.getPath());      long availableBlocks = s.getAvailableBlocksLong();      long blockCount = s.getBlockCountLong();      long blockSize = s.getBlockSizeLong();      long totalsize = blockSize * blockCount;      long availsize = blockSize * availableBlocks;      String totalsizeStr = Formatter.formatFileSize(context, totalsize);      String availsizeStr = Formatter.formatFileSize(context, availsize);    } catch (Exception e) {      e.printStackTrace();    }  }  /**   * 手机内存   * @param context   */  public static void getDataInfo(Context context){    try {      File path = Environment.getDataDirectory();      StatFs s = new StatFs(path.getPath());      long availableBlocks = s.getAvailableBlocksLong();      long blockCount = s.getBlockCountLong();      long blockSize = s.getBlockSizeLong();      long totalsize = blockSize * blockCount;      long availsize = blockSize * availableBlocks;      String totalsizeStr = Formatter.formatFileSize(context, totalsize);      String availsizeStr = Formatter.formatFileSize(context, availsize);    } catch (Exception e) {      e.printStackTrace();    }  }}

希望本文所述对大家Android程序设计有所帮助。


注:相关教程知识阅读请移步到Android开发频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表