当前位置: 代码迷 >> Android >> Android 最新获取手机内置存储大小,SD卡存储空间大小步骤
  详细解决方案

Android 最新获取手机内置存储大小,SD卡存储空间大小步骤

热度:54   发布时间:2016-04-28 03:30:13.0
Android 最新获取手机内置存储大小,SD卡存储空间大小方法

在以前我们都是这样获取的

//Android API18之前:fs.getAvailableBlocks()*fs.getBlockSize()

目前:

/** 得到系统可用内存 **/	@SuppressLint("NewApi")	private String getMemFree(){		StatFs fs = new StatFs(Environment.getDataDirectory().getPath());		return Formatter.formatFileSize(this, (fs.getAvailableBytes()));	}		/** 得到SD可用内存 **/	@SuppressLint("NewApi")	private String getSdFree(){		if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ 			StatFs fs = new StatFs(Environment.getExternalStorageDirectory().getPath());			//Android API18之前:fs.getAvailableBlocks()*fs.getBlockSize()			return Formatter.formatFileSize(this, (fs.getAvailableBytes()));		}		return "未装载";	}


终于解决问题了,嘎嘎

  相关解决方案