获取应用图标并转为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; }
相关推荐
MIKUScallion 2020-01-10
博了个客 2020-05-31
lixiaotao 2020-03-05
调调 2013-07-24
83580494 2013-06-29
TongsengsBlog 2013-08-27
Android进阶 2013-08-25
89143951 2011-08-25
八角塘塘主 2019-10-29
lerayZhang 2015-01-11
timewind 2019-07-01
Ashes 2019-06-30
learningITwell 2019-06-28
PGzxc 2019-06-28
xusong 2012-08-01
Android进阶 2019-06-27
helowken 2019-06-21
飞奔的熊猫 2019-06-21
solarsaber 2015-07-24