PackageManager packageManager = context.getPackageManager();
ApplicationInfo appInfo = packageManager.getApplicationInfo(packageName, 0);
Drawable icon = appInfo.loadIcon(packageManager);
Bitmap bitmap;
try {
if (Build.VERSION.SDK_INT >= 26 && icon instanceof AdaptiveIconDrawable) {
bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
icon.draw(canvas);
} else {
bitmap = ((BitmapDrawable) icon).getBitmap();
}
} catch (Exception e) {
}