当前位置:网站首页>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();
}
}边栏推荐
- matplotlib绘图润色(如何形成高质量的图,例如设如何置字体等)
- Leetcode (347) - top k high frequency elements
- CTF逆向基础
- Abbkine BCA法 蛋白质定量试剂盒说明书
- CADD course learning (7) -- Simulation of target and small molecule interaction (semi flexible docking autodock)
- 2022北京眼睛健康用品展,护眼产品展,中国眼博会11月举办
- 1、强化学习基础知识点
- 如何让化工企业的ERP库存账目更准确
- Informatics Olympiad 1337: [example 3-2] word search tree | Luogu p5755 [noi2000] word search tree
- 14、Transformer--VIT TNT BETR
猜你喜欢

Norgen AAV提取剂盒说明书(含特色)

Classic implementation of the basic method of intelligent home of Internet of things

2022 Beijing eye health products exhibition, eye care products exhibition, China eye Expo held in November

Norgen AAV extractant box instructions (including features)

线程池的使用

2022北京眼睛健康用品展,护眼产品展,中国眼博会11月举办

小程序页面导航

How to form standard interface documents

Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书

Abnova maxpab mouse derived polyclonal antibody solution
随机推荐
2.8 basic knowledge of project management process
Is it safe to open an account online? Where can I get a low commission?
[Yugong series] go teaching course in July 2022 004 go code Notes
2020 CCPC Weihai - A. golden spirit (thinking), D. ABC project (big number decomposition / thinking)
Is it safe to open a stock account by mobile phone? My home is relatively remote. Is there a better way to open an account?
Selenium element information
Chemical properties and application instructions of prosci Lag3 antibody
当Steam教育进入个性化信息技术课程
常用的视图容器类组件
Relationship between mongodb documents
重上吹麻滩——段芝堂创始人翟立冬游记
mongodb基操的练习
鸿蒙系统控制LED的实现方法之经典
Abnova丨血液总核酸纯化试剂盒预装相关说明书
线程池的使用
How to renew NPDP? Here comes the operation guide!
【刷题记录】1. 两数之和
台风来袭!建筑工地该如何防范台风!
Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书
Schema and model