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



相关文章:

  • 2021-05-24
  • 2022-02-10
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-02-04
相关资源
相似解决方案