亲宝软件园·资讯

展开

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

LovooGod 人气:0
想了解Android开发实现的获取sdcard大小及内存大小工具类的相关内容吗,LovooGod在本文为您仔细讲解Android获取sdcard大小及内存大小的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android,sdcard,内存,下面大家一起来学习吧。

本文实例讲述了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程序设计有所帮助。

加载全部内容

相关教程
猜你喜欢
用户评论