现在的位置: 首页 > 综合 > 正文

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

2018年02月23日 ⁄ 综合 ⁄ 共 614字 ⁄ 字号 评论关闭

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

//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 "未装载";
	}

终于解决问题了,嘎嘎

抱歉!评论已关闭.