当前位置:网站首页>Android clear app cache
Android clear app cache
2022-04-23 13:20:00 【lebulangzhen】
The first one is
Use ActivityManager Medium clearApplicationUserData Method , The code is as follows :
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
am.clearApplicationUserData();
The problem with this approach is that it doesn't just clear cache, Jointly applied data Also deleted . As shown in the figure below :
The second kind
Use PackageManager Medium deleteApplicationCacheFiles Method , This API It's hidden , So you need to use reflection to call , The code is as follows :
PackageManager packageManager = context.getPackageManager();
Method method;
try {
method = PackageManager.class.getDeclaredMethod("deleteApplicationCacheFiles", String.class, IPackageDataObserver.class);
method.invoke(packageManager, packageName, new ClearUserDataObserver());
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
static class ClearUserDataObserver extends IPackageDataObserver.Stub {
public void onRemoveCompleted(final String packageName, final boolean succeeded) {
Log.i(TAG, "IPackageDataObserver succeeded: " + succeeded);
}
}
This method will only clear cache, If necessary, just clear the cache , It can be in this way .IPackageDataObserver You need to put yourself in the project aidi In the folder , As shown in the figure below :
Both methods require system permission , It can be called successfully only when it is declared as a system application and signed by the system .
版权声明
本文为[lebulangzhen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230607407830.html
边栏推荐
- [point cloud series] summary of papers related to implicit expression of point cloud
- AUTOSAR from introduction to mastery lecture 100 (84) - Summary of UDS time parameters
- [quick platoon] 215 The kth largest element in the array
- [point cloud series] foldingnet: point cloud auto encoder via deep grid deformation
- Vscode tips
- These vscode extensions are my favorite
- [point cloud series] unsupervised multi task feature learning on point clouds
- 浅谈js正则之test方法bug篇
- Uniapp image import local image not displayed
- Metalama简介4.使用Fabric操作项目或命名空间
猜你喜欢

100 GIS practical application cases (53) - making three-dimensional image map as the base map of urban spatial pattern analysis

Servlet of three web components

Common interview questions and detailed analysis of the latest Android developers in 2020
![[Journal Conference Series] IEEE series template download guide](/img/1b/a3cf2688778ec34354e77e28e32be8.png)
[Journal Conference Series] IEEE series template download guide

Solve the problem that Oracle needs to set IP every time in the virtual machine

CSDN高校俱乐部“名师高校行”——湖南师范大学站

在 pytorch 中加载和使用图像分类数据集 Fashion-MNIST

The first lesson is canvas, showing a small case
![[dynamic programming] 221 Largest Square](/img/31/3af4ba05764a683220b5292d3b8780.png)
[dynamic programming] 221 Largest Square

Imx6ull QEMU bare metal tutorial 1: GPIO, iomux, I2C
随机推荐
POM of SSM integration xml
mui picker和下拉刷新冲突问题
Playwright contrôle l'ouverture de la navigation Google locale et télécharge des fichiers
Armv8m (cortex M33) MPU actual combat
“湘见”技术沙龙 | 程序员&CSDN的进阶之路
叮~ 你的奖学金已到账!C认证企业奖学金名单出炉
uniapp image 引入本地图片不显示
Ding ~ your scholarship has arrived! C certified enterprise scholarship list released
TCP 复位gongji原理和实战复现
SSM整合之pom.xml
Loading and using image classification dataset fashion MNIST in pytorch
超40W奖金池等你来战!第二届“长沙银行杯”腾讯云启创新大赛火热来袭!
MySQL5.5安装教程
【动态规划】221. 最大正方形
playwright控制本地谷歌浏览打开,并下载文件
SPI NAND flash summary
[dynamic programming] 221 Largest Square
2020年最新字节跳动Android开发者常见面试题及详细解析
vscode小技巧
Migrating your native/mobile application to Unified Plan/WebRTC 1.0 API