当前位置:网站首页>Clear app data and get Icon
Clear app data and get Icon
2022-07-05 20:43:00 【Novice Xiaowang】
1. eliminate data
need Configure permissions
<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;
}
perhaps
try {
Process exec = Runtime.getRuntime().exec("pm clear " + pkg);
exec.getInputStream().read(clearDataResult); To get the results
} catch (IOException e) {
e.printStackTrace();
}
2. obtain app Icon
PackageManager pm = getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo(getPackageName(),0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Drawable drawable = packageInfo.applicationInfo.loadIcon(pm);
preservation 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. Simulate click events
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. Simulate sliding events
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();
}
}
边栏推荐
- Usaco3.4 "broken Gong rock" band raucous rockers - DP
- Applet event binding
- Schema and model
- Informatics Olympiad 1340: [example 3-5] extended binary tree
- 台风来袭!建筑工地该如何防范台风!
- Frequent MySQL operations cause table locking problems
- Dry goods navigation in this quarter | Q2 2022
- Abnova fluorescent dye 620-m streptavidin scheme
- 2.8、项目管理过程基础知识
- Is the securities account given by the school of Finance and business safe? Can I open an account?
猜你喜欢
ProSci LAG-3 重组蛋白说明书
Applet page navigation
Fundamentals - configuration file analysis
Station B up builds the world's first pure red stone neural network, pornographic detection based on deep learning action recognition, Chen Tianqi's course progress of machine science compilation MLC,
当Steam教育进入个性化信息技术课程
2022 Beijing eye health products exhibition, eye care products exhibition, China eye Expo held in November
Norgen AAV提取剂盒说明书(含特色)
Unity editor extended UI control
Duchefa丨P1001植物琼脂中英文说明书
Abnova maxpab mouse derived polyclonal antibody solution
随机推荐
清除app data以及获取图标
王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
How to renew NPDP? Here comes the operation guide!
【愚公系列】2022年7月 Go教学课程 004-Go代码注释
National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition
Abnova total RNA Purification Kit for cultured cells Chinese and English instructions
1. Strengthen learning basic knowledge points
Graph embedding learning notes
Mongodb/ document operation
IC popular science article: those things about Eco
Y57. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (30)
Nprogress plug-in progress bar
Abbkine BCA法 蛋白质定量试剂盒说明书
phpstudy小皮的mysql点击启动后迅速闪退,已解决
解读协作型机器人的日常应用功能
Duchefa丨MS培养基含维生素说明书
Abnova丨E (DIII) (WNV) 重组蛋白 中英文说明书
培养机器人教育创造力的前沿科技
Use of form text box (II) input filtering (synthetic event)
小程序全局配置