Welcome

首页 / 移动开发 / Android / Android安卓中循环录像并检测内存卡容量

/** * 循环录像,当内存卡容量少于300M时,自动删除视频列表里面的第一个文件 */private void xunhuanluxiang() {if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {File path = Environment.getExternalStorageDirectory();// 取得sdcard文件路径StatFs statfs = new StatFs(path.getPath());// 获取block的SIZElong blocSize = statfs.getBlockSize();// 获取BLOCK数量long totalBlocks = statfs.getBlockCount();// 己使用的Block的数量long availaBlock = statfs.getAvailableBlocks();// 获取当前可用内存容量,单位:MBlong sd = availaBlock * blocSize / 1024 / 1024;if (sd < 300) {String filepath = (Environment.getExternalStorageDirectory().getAbsolutePath() + "/video/");File file = new File(filepath);if (!file.exists()) {file.mkdirs();}File[] files = file.listFiles();if (files.length > 0) {String childFile[] = file.list();String dele = (filepath + childFile[0]);File file2 = new File(dele);file2.delete();}}} else if (Environment.getExternalStorageState().equals(Environment.MEDIA_REMOVED)) {Toast.makeText(this, "请插入内存卡", Toast.LENGTH_SHORT).show();}}