uniapp如何清理缓存和广告下载的apk安装包文件

uniapp加入了广告之后,点击广告下载的apk使应用占用的存储越来越高,这些文件如何删除。

// plus.io.requestFileSystem 请求本地文件系统对象 
// plus.io.PUBLIC_DOWNLOADS 应用公共下载目录,多应用时都可读写,常用于保存下载文件
// 详细介绍请查看官方文档
plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, function(fs) {

  // 对应Android系统应用外部存储目录(通常为“/sdcard/Android/data/%PACKAGENAME%/”,其中%PACKAGENAME%是程序的包名)下的"downloads"目录
  const path = fs.root.fullPath
  // 查看手机文件夹发现,广告apk是在 “/sdcard/Android/data/%PACKAGENAME%/files”文件夹下面,
  const apkFilePath = path.replace('downloads/', 'files/')
  // 调用删除方法
  clearFiles(apkFilePath)

→查看完整代码

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
清理uniapp页面缓存,可以按照以下步骤进行操作: 1. 在HTML部分,添加一个触发清理缓存操作的按钮: ```html <view class="li" @click="clearStorage">清理缓存 <text class="current-size">{{currentSize}}</text> <uni-icons type="arrowright" size="18" color="#ddd" class="fr"></uni-icons></view> ``` 2. 在script的js部分,定义清理缓存相关的方法和获取缓存大小的方法: ```javascript data() { return { storageSize: '0M', } }, onLoad() { this.getStorageSize() //获取缓存 }, methods: { //获取app的缓存大小 getStorageSize: function () { let that = this; uni.getStorageInfo({ success(res) { let size = res.currentSize; if (size < 1024) { that.storageSize = size + ' B'; } else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) { that.storageSize = Math.floor(size / 1024 * 100) / 100 + ' KB'; } else if (size / 1024 / 1024 >= 1) { that.storageSize = Math.floor(size / 1024 / 1024 * 100) / 100 + ' M'; } } }) }, //删除缓存 clearStorage: function () { let that = this; uni.showModal({ title: '提示', content: '确定清除缓存吗?', confirmText: '立即清除', success(res) { if (res.confirm) { uni.clearStorageSync(); that.getStorageSize(); //重新获取并显示清除后的缓存大小 uni.showToast({ title: '清除成功', icon: 'none' }) //清除完后跳到登录页面 setTimeout(() => { uni.redirectTo({ url: '/pages/login/login', animationType: 'pop-in', animationDuration: 200 }) }, 1300) } } }) }, } ``` 3. 在组件里添加一个触发清理缓存的事件: ```html <view class="row" @click="clearStorage"> <view class="title">清除缓存</view> <view class="right"> <view class="tis tell">{{storageSize}}</view> <uni-icons type="arrowright" color="#C9C9C9" size="20"></uni-icons> </view> </view> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值