当前位置:网站首页>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();
}
}
边栏推荐
- 14、Transformer--VIT TNT BETR
- Norgen AAV extractant box instructions (including features)
- Point cloud file Dat file read save
- 鸿蒙系统控制LED的实现方法之经典
- PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
- 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?
- Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Nanjing
- 19 mongoose modularization
- 14、Transformer--VIT TNT BETR
- When JS method passes long type ID value, precision loss will occur
猜你喜欢
Norgen AAV extractant box instructions (including features)
Unity editor extended UI control
Abnova blood total nucleic acid purification kit pre installed relevant instructions
Duchefa p1001 plant agar Chinese and English instructions
Hongmeng OS' fourth learning
Duchefa细胞分裂素丨二氢玉米素 (DHZ)说明书
Mysql频繁操作出现锁表问题
1. Strengthen learning basic knowledge points
Applet event binding
Welcome to the game and win rich bonuses: Code Golf Challenge officially launched
随机推荐
小程序项目结构
Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
Duchefa丨D5124 MD5A 培养基中英文说明书
mongodb/文档操作
Minimum commission for stock trading account opening, where to open an account with low commission? Is it safe to open an account on your mobile phone
挖财商学院给的证券账户安全吗?可以开户吗?
资源道具化
CTF逆向基础
Norgen AAV extractant box instructions (including features)
鸿蒙os第四次学习
3.3 project evaluation
小程序全局配置
Return to blowing marshland -- travel notes of zhailidong, founder of duanzhitang
Mongodb basic exercises
19 mongoose modularization
Frequent MySQL operations cause table locking problems
go 文件路径操作
Applet project structure
Abnova CD81 monoclonal antibody related parameters and Applications
Point cloud file Dat file read save