当前位置:网站首页>清除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();
}
}
边栏推荐
- Duchefa细胞分裂素丨二氢玉米素 (DHZ)说明书
- IC popular science article: those things about Eco
- 2.8 basic knowledge of project management process
- Applet global configuration
- 2022 Beijing eye health products exhibition, eye care products exhibition, China eye Expo held in November
- [quick start of Digital IC Verification] 7. Basic knowledge of digital circuits necessary for verification positions (including common interview questions)
- mysql全面解析json/数组
- CVPR 2022 | common 3D damage and data enhancement
- National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition
- kubernetes资源对象介绍及常用命令(五)-(ConfigMap&Secret)
猜你喜欢
随机推荐
Abbkine丨TraKine F-actin染色试剂盒(绿色荧光)方案
sort和投影
证券开户选择哪个证券比较好?网上开户安全么?
Abnova丨 MaxPab 小鼠源多克隆抗体解决方案
基础篇——配置文件解析
CVPR 2022 | common 3D damage and data enhancement
死信队列入门(两个消费者,一个生产者)
Abnova丨DNA 标记高质量控制测试方案
[quick start of Digital IC Verification] 9. Finite state machine (FSM) necessary for Verilog RTL design
信息学奥赛一本通 1338:【例3-3】医院设置 | 洛谷 P1364 医院设置
Redis唯一ID生成器的实现
Make Jar, Not War
Codeforces Round #804 (Div. 2) - A, B, C
Applet project structure
document方法
信息学奥赛一本通 1339:【例3-4】求后序遍历 | 洛谷 P1827 [USACO3.4] 美国血统 American Heritage
ROS2专题【01】:win10上安装ROS2
[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives
Unity editor extended UI control
Usaco3.4 "broken Gong rock" band raucous rockers - DP