📚往期笔录记录🔖:
🔖鸿蒙(HarmonyOS)北向开发知识点记录~
🔖鸿蒙(OpenHarmony)南向开发保姆级知识点汇总~
🔖鸿蒙应用开发与鸿蒙系统开发哪个更有前景?
🔖嵌入式开发适不适合做鸿蒙南向开发?看完这篇你就了解了~
🔖对于大前端开发来说,转鸿蒙开发究竟是福还是祸?
🔖鸿蒙岗位需求突增!移动端、PC端、IoT到底该怎么选?
🔖记录一场鸿蒙开发岗位面试经历~
🔖持续更新中……
使用接口
接口 | 接口能力 |
---|---|
storageStatistics.getCurrentBundleStats | 获取当前应用的存储空间大小 (包含缓存文件,安装文件等) |
statvfs.getFreeSize | 查询设备剩余可用空间 |
statvfs.getTotalSize | 获取设备总空间 (排除系统占用空间) |
场景一:计算应用缓存大小 , 并进行清理
1.可以通过storageStatistics.getCurrentBundleStats接口获取缓存大小。
应用的缓存文件因为级别和加密类型不同,会保存在以下目录中。例如:app级别,加密类型为el1的缓存会保存到/data/storage/el1/base/cache目录下。
/data/storage/el1/base/cache
/data/storage/el1/base/haps/entry/cache
/data/storage/el2/base/cache
/data/storage/el2/base/haps/entry/cache
这四个目录可以通过以下接口获取,其中el1与el2因为分区不同,需要切换加密等级才能获取到:
let moduleContext: common.Context;
moduleContext = this.context.createModuleContext('entry');
console.log('moduleContext + el2: '+moduleContext.cacheDir);
console.log('UIAbilityContext + el2: '+this.context.cacheDir);
moduleContext.area = contextConstant.AreaMode.EL1;
console.log('moduleContext + el1: '+moduleContext.cacheDir);
this.context.area = contextConstant.AreaMode.EL1;
console.log('UIAbilityContext + el1: '+this.context.cacheDir);