当前位置:网站首页>清除app data以及获取图标
清除app data以及获取图标
2022-07-05 20:36:00 【菜鸟xiaowang】
1.清除data
需要 配置权限
<uses-permission android:name="android.permission.ACCESS_INSTANT_APPS"/>
public static boolean clearData(String pkg){
Context context = HwContext.getContext();
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
am.clearApplicationUserData(pkg,null);
return true;
}
或者
try {
Process exec = Runtime.getRuntime().exec("pm clear " + pkg);
exec.getInputStream().read(clearDataResult);获取结果
} catch (IOException e) {
e.printStackTrace();
}
2.获取app 图标
PackageManager pm = getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo(getPackageName(),0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Drawable drawable = packageInfo.applicationInfo.loadIcon(pm);
保存icon
Drawable icon = t.getIcon();
File file = new File("icon.png");
try {
Bitmap bm = drawableToBitmap(icon);
FileOutputStream out = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
public Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap = Bitmap.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
// canvas.setBitmap(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
3.模拟点击事件
public void constructClickEvent(int x,int y){
List<String> commands = new ArrayList<String>();
commands.add("input");
commands.add("tap");
commands.add("" + x);
commands.add("" + y);
try {
Process start = new ProcessBuilder(commands).start();
} catch (IOException e) {
e.printStackTrace();
}
}
4.模拟滑动事件
public void constructSlideEvent(int x,int y,int newX,int newY){
InputStream is = null;
ByteArrayOutputStream baos = null;
List<String> commands = new ArrayList<String>();
commands.add("input");
commands.add("swipe");
commands.add("" + x);
commands.add("" + y);
commands.add("" + newX);
commands.add("" + newY);
ProcessBuilder pb = new ProcessBuilder(commands);
try {
Process prs = pb.start();
} catch (IOException e) {
e.printStackTrace();
}
}
边栏推荐
- Unity editor extended UI control
- Practical demonstration: how can the production research team efficiently build the requirements workflow?
- Oracle tablespace management
- Abnova 环孢素A单克隆抗体,及其研究工具
- 物联网智能家居基本方法实现之经典
- About the priority of Bram IP reset
- 信息学奥赛一本通 1338:【例3-3】医院设置 | 洛谷 P1364 医院设置
- Dry goods navigation in this quarter | Q2 2022
- 1、强化学习基础知识点
- 【UE4】UnrealInsight获取真机性能测试报告
猜你喜欢
[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives
全国爱眼教育大会,2022第四届北京国际青少年眼健康产业展会
Leetcode (695) - the largest area of an island
Abnova丨CRISPR SpCas9 多克隆抗体方案
2.8、项目管理过程基础知识
Leetcode brush questions: binary tree 18 (largest binary tree)
AI 从代码中自动生成注释文档
欢迎来战,赢取丰厚奖金:Code Golf 代码高尔夫挑战赛正式启动
Informatics Orsay all in one 1339: [example 3-4] find the post order traversal | Valley p1827 [usaco3.4] American Heritage
[quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design
随机推荐
Redis唯一ID生成器的实现
Kubernetes resource object introduction and common commands (V) - (configmap & Secret)
National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition
2.8 basic knowledge of project management process
Leetcode skimming: binary tree 17 (construct binary tree from middle order and post order traversal sequence)
ProSci LAG-3 重组蛋白说明书
Usaco3.4 "broken Gong rock" band raucous rockers - DP
常用的视图容器类组件
插值查找的简单理解
How to form standard interface documents
ROS2专题【01】:win10上安装ROS2
nprogress插件 进度条
【数字IC验证快速入门】1、浅谈数字IC验证,了解专栏内容,明确学习目标
Informatics Olympiad 1340: [example 3-5] extended binary tree
证券开户选择哪个证券比较好?网上开户安全么?
NPDP如何续证?操作指南来了!
Abnova 环孢素A单克隆抗体,及其研究工具
[quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design
如何形成规范的接口文档
[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives