码迷,mamicode.com
首页 > 移动开发 > 详细

Android 推断SD卡是否存在及容量查询

时间:2017-07-20 22:28:36      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:turn   files   count()   ems   white   tracking   androi   容量   res   

首先先要加入权限
<uses-permission android :name ="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android: name="android.permission.WRITE_EXTERNAL_STIRAGE"/>


推断SD卡是否存在

	/*
	 * 推断SD卡是否存在
	 */
	private boolean ExitSDcard() {
		if (Environment.getExternalStorageState().equals(
				android.os.Environment.MEDIA_UNMOUNTED)) {
			return true;
		} else {
			return false;
		}
	}

<span style="white-space:pre">	</span>/*
	 * 查看SD卡总容量
	 */
	@SuppressWarnings("deprecation")
	public long getSDAllSize() {
		String path = Environment.getExternalStorageDirectory().getPath();
		StatFs sf = new StatFs(path);
		int blockSize = sf.getBlockSize();

		int allBlocks = sf.getBlockCount();
		return (allBlocks * blockSize) / 1024 / 1024;

	}
/*
	 * 
	 * 查看SD卡剩余空间
	 */
	@SuppressWarnings("deprecation")
	public long getSDFreeSize() {
		String path = Environment.getExternalStorageDirectory().getPath();
		StatFs statFs = new StatFs(path);
		int size = statFs.getBlockSize();
		int freeBlocks = statFs.getAvailableBlocks();
		return (freeBlocks * size) / 1024 / 1024;
	}



Android 推断SD卡是否存在及容量查询

标签:turn   files   count()   ems   white   tracking   androi   容量   res   

原文地址:http://www.cnblogs.com/brucemengbm/p/7214524.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!