获取应用图标时,8.0以上系统会报.AdaptiveIconDrawable.getOutline(AdaptiveIconDrawable.java:405)和AdaptiveIconDrawable.isProjected错误,导致项目崩溃。是因为8.0以后Google添加了自适应图标AdaptiveIconDrawable,所以获取图标使用下面的方法
@RequiresApi(api = Build.VERSION_CODES.O)
public static Bitmap getAppIconFor8(Context context, String packageName) {
PackageManager mPackageManager = context.getPackageManager();
Bitmap bitmap =null;
try {
Drawable drawable = mPackageManager.getApplicationIcon(packageName);
if (drawable instanceof BitmapDrawable) {
bitmap =((BitmapDrawable) drawable).getBitmap();
} else if (drawable instanceof AdaptiveIconDrawable) {
int j = drawable.getIntrinsicWidth();
int k = drawable.getIntrinsicHeight();
int i = j;
if (j <= 0) {
i = 1;