欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android安卓中循环录像并检测内存卡容量

程序员文章站 2022-06-04 12:17:25
/** * 循环录像,当内存卡容量少于300m时,自动删除视频列表里面的第一个文件 */ private void xunhuanluxiang()...
/**
	 * 循环录像,当内存卡容量少于300m时,自动删除视频列表里面的第一个文件
	 */
	private void xunhuanluxiang() {
		if (environment.getexternalstoragestate().equals(
				environment.media_mounted)) {
			file path = environment.getexternalstoragedirectory();
			// 取得sdcard文件路径
			statfs statfs = new statfs(path.getpath());
			// 获取block的size
			long blocsize = statfs.getblocksize();
			// 获取block数量
			long totalblocks = statfs.getblockcount();
			// 己使用的block的数量
			long availablock = statfs.getavailableblocks();
			// 获取当前可用内存容量,单位:mb
			long 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();
		}
	}