欢迎光临
我们一直在努力

全自动清除缓冲代码

-程序启动时会执行的事件 import “java.io.File” import “android.text.format.Formatter”–获取文件夹大小function getFolderSize(folderPath,conversion) import “java.io.*” local size = 0 local fileList = luajava.astable(File(folderPath).listFiles()) if(fileList == nil) then return 0 end –开始遍历循环获取文件夹底下所有文件的字节大小 if(fileList ~= nil) then for count=1,#fileList do if(File(tostring(fileList[count])).isDirectory()) then size = size + getFolderSize(tostring(fileList[count])) else local singleFileSize = File(tostring(fileList[count])).length() size = size + singleFileSize end end end –字节换算 if(conversion == true) then local GB = 1024 * 1024 * 1024;–定义GB的计算常量 local MB = 1024 * 1024;–定义MB的计算常量 local KB = 1024;–定义KB的计算常量 local countResult = “” if(size / GB >= 1) then –如果当前Byte的值大于等于1GB countResult = string.format(“%.2f”,size / GB)..”GB” return countResult elseif (size / MB >= 1) then –如果当前Byte的值大于等于1MB countResult = string.format(“%.2f”,size / MB)..”MB” return countResult elseif (size / KB >= 1) then –如果当前Byte的值大于等于1KB countResult = string.format(“%.2f”,size / KB)..”KB” return countResult else countResult = size..”B” return countResult end elseif(conversion == nil or conversion == false) then return size endend–x5视频缓存大于1000m自动清除if File(“/sdcard/Android/data/”..this.packageName..”/files/VideoCache/main/”).exists() or File(“storage/emulated/0/Android/data/”..this.packageName..”/files/VideoCache/main/”).exists()then if (getFolderSize(“/sdcard/Android/data/”..this.packageName..”/files/VideoCache/main/”,false)>1000000000) or (getFolderSize(“/storage/emulated/0/Android/data/”..this.packageName..”/files/VideoCache/main/”,false)>1000000000) then 执行Shell(“rm -rf /sdcard/Android/data/”..this.packageName..”/files/VideoCache/main/”) 执行Shell(“rm -rf /storage/emulated/0/Android/data/”..this.packageName..”/files/VideoCache/main/”) endend

赞(0)
未经允许不得转载:阿强爱分享 » 全自动清除缓冲代码

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址