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相关内容感兴趣的读者可查看本站专题:《Android编程开发之SD卡操作方法汇总》、《Android文件操作技巧汇总》、《Android数据库操作技巧总结》、《Android编程之activity操作技巧总结》、《Android开发入门与进阶教程》、《Android资源操作技巧汇总》、《Android视图View技巧总结》及《Android控件用法总结》
希望本文所述对大家Android程序设计有所帮助。
赞 (0)