萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> 安卓開發 >> Android安卓中循環錄像並檢測內存卡容量

Android安卓中循環錄像並檢測內存卡容量

 這篇文章主要介紹了Android安卓中循環錄像並檢測內存卡容量,當內存卡空間已滿時,本文還實現自動刪除視頻列表裡面的第一個文件,需要的朋友可以參考下

    ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 /** * 循環錄像,當內存卡容量少於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(); } }
copyright © 萬盛學電腦網 all rights reserved