循环录像,听起来是不是很高大上,其实原理就是检测内存卡容量,少于一定值就自动删除指定的文件夹,这个做监控或者行车记录仪会用得着。


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