zoukankan      html  css  js  c++  java
  • Android 推断SD卡是否存在及容量查询

    首先先要加入权限
    <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;
    	}



  • 相关阅读:
    牛客算法周周练2
    牛客算法周周练2
    2020年7月7日Java学习日记
    2020年7月6日Java学习日记
    练习29--if语句
    练习28--布尔练习
    练习27--记忆逻辑
    第18~19讲课后作业
    第20讲:内嵌函数和闭包
    练习25--更多更多练习
  • 原文地址:https://www.cnblogs.com/brucemengbm/p/7214524.html
Copyright © 2011-2022 走看看