获取应用图标并转为bitmap适配android10
Posted 办法总比问题多
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取应用图标并转为bitmap适配android10相关的知识,希望对你有一定的参考价值。
/** * 获取图标 bitmap * * @param context * Context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)//android 10存储图片地址 */ public static synchronized Bitmap getBitmap(Context context) { PackageManager packageManager = null; ApplicationInfo applicationInfo = null; try { packageManager = context.getApplicationContext() .getPackageManager(); applicationInfo = packageManager.getApplicationInfo( context.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { applicationInfo = null; } Drawable d = packageManager.getApplicationIcon(applicationInfo); //xxx根据自己的情况获取drawable Bitmap APKicon; if(d instanceof BitmapDrawable) { APKicon = ((BitmapDrawable)d).getBitmap(); }else{ Bitmap bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(),d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); d.draw(canvas); APKicon = bitmap; } // BitmapDrawable bd = (BitmapDrawable) d; // Bitmap bm = bd.getBitmap(); return APKicon; }
以上是关于获取应用图标并转为bitmap适配android10的主要内容,如果未能解决你的问题,请参考以下文章