当前位置:网站首页>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
边栏推荐
- [Journal Conference Series] IEEE series template download guide
- 100 GIS practical application cases (52) - how to keep the number of rows and columns consistent and aligned when cutting grids with grids in ArcGIS?
- Vscode tips
- hbuilderx + uniapp 打包ipa提交App store踩坑记
- @Excellent you! CSDN College Club President Recruitment!
- 普通大学生如何拿到大厂offer?敖丙教你一招致胜!
- MySQL -- 16. Data structure of index
- [point cloud series] unsupervised multi task feature learning on point clouds
- [wechat applet] flex layout usage record
- 榜样专访 | 孙光浩:高校俱乐部伴我成长并创业
猜你喜欢
Solve the problem that Oracle needs to set IP every time in the virtual machine
web三大组件之Servlet
Nodejs + websocket cycle small case
You and the 42W bonus pool are one short of the "Changsha bank Cup" Tencent yunqi innovation competition!
Esp32 vhci architecture sets scan mode for traditional Bluetooth, so that the device can be searched
GIS practical tips (III) - how to add legend in CASS?
AUTOSAR from introduction to mastery lecture 100 (84) - Summary of UDS time parameters
Lpddr4 notes
How to build a line of code with M4 qprotex
100000 college students have become ape powder. What are you waiting for?
随机推荐
【快排】215. 数组中的第K个最大元素
MySQL5. 5 installation tutorial
4.22 study record (you only did water problems in one day, didn't you)
Playwright controls local Google browsing to open and download files
Pyqt5 store opencv pictures into the built-in sqllite database and query
100 GIS practical application cases (53) - making three-dimensional image map as the base map of urban spatial pattern analysis
Stack protector under armcc / GCC
nodeJs + websocket 循环小案例
GIS practical tips (III) - how to add legend in CASS?
[point cloud series] multi view neural human rendering (NHR)
The first lesson is canvas, showing a small case
2020年最新字节跳动Android开发者常见面试题及详细解析
mysql 基本语句查询
100 GIS practical application cases (51) - a method for calculating the hourly spatial average of NC files according to the specified range in ArcGIS
[dynamic programming] 221 Largest Square
[point cloud series] Introduction to scene recognition
[point cloud series] foldingnet: point cloud auto encoder via deep grid deformation
[walking notes]
FFmpeg常用命令
【微信小程序】flex布局使用记录