当前位置: 代码迷 >> Android >> Android之获取SD卡总容量,可用大小,机身内存储器总容量及可用大小的系统方法
  详细解决方案

Android之获取SD卡总容量,可用大小,机身内存储器总容量及可用大小的系统方法

热度:85   发布时间:2016-04-28 05:06:12.0
Android之获取SD卡总容量,可用大小,机身内存总容量及可用大小的系统方法
/**	 * 获得SD卡总大小	 * 	 * @return	 */	private String getSDTotalSize() {		File path = Environment.getExternalStorageDirectory();		StatFs stat = new StatFs(path.getPath());		long blockSize = stat.getBlockSize();		long totalBlocks = stat.getBlockCount();		return Formatter.formatFileSize(MainActivity.this, blockSize * totalBlocks);	}	/**	 * 获得sd卡剩余容量,即可用大小	 * 	 * @return	 */	private String getSDAvailableSize() {		File path = Environment.getExternalStorageDirectory();		StatFs stat = new StatFs(path.getPath());		long blockSize = stat.getBlockSize();		long availableBlocks = stat.getAvailableBlocks();		return Formatter.formatFileSize(MainActivity.this, blockSize * availableBlocks);	}	/**	 * 获得机身内存总大小	 * 	 * @return	 */	private String getRomTotalSize() {		File path = Environment.getDataDirectory();		StatFs stat = new StatFs(path.getPath());		long blockSize = stat.getBlockSize();		long totalBlocks = stat.getBlockCount();		return Formatter.formatFileSize(MainActivity.this, blockSize * totalBlocks);	}	/**	 * 获得机身可用内存	 * 	 * @return	 */	private String getRomAvailableSize() {		File path = Environment.getDataDirectory();		StatFs stat = new StatFs(path.getPath());		long blockSize = stat.getBlockSize();		long availableBlocks = stat.getAvailableBlocks();		return Formatter.formatFileSize(MainActivity.this, blockSize * availableBlocks);	}
  相关解决方案