软件编程
位置:首页>> 软件编程>> Android编程>> Android安卓中循环录像并检测内存卡容量

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

作者:junjie  发布时间:2021-06-21 13:12:55 

标签:Android,安卓,循环录像,检测,内存卡,容量

/**
* 循环录像,当内存卡容量少于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();
}
}
0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com