获取应用图标直接使用,有些会撑破布局,需要固定大小。
https://blog.51cto.com/u_16213367/8811342
BitmapDrawable 可以强制转换,其他类型Drawable需要重绘。
AdaptiveIconDrawable cannot be cast to BitmapDrawable
https://blog.csdn.net/u011905115/article/details/96434062
NinePatchDrawable cannot be cast to BitmapDrawable
https://blog.csdn.net/Kitty_Landon/article/details/49493717
Drawable icon = packageInfo.applicationInfo.loadIcon(PM);
AppInfo appInfo = new AppInfo();
appInfo.setAppIcon(resizeDrawable(getApplicationContext(), icon, 200, 200));Drawable resizeDrawable(Context context, Drawable drawable, int newWidth, int newHeight) {// 将Drawable转换为Bitmap Bitmap bitmap;if (drawable instanceof BitmapDrawable) {bitmap = ((BitmapDrawable) drawable).getBitmap();} else {bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);Canvas canvas = new Canvas(bitmap);drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());drawable.draw(canvas);}// 缩放BitmapBitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false);// 将Bitmap转换为Drawablereturn new BitmapDrawable(context.getResources(), resizedBitmap);
}