I'm trying to show some applications' icons on an Android widget.
I can get the icon as a drawable with:
Drawable d = context.getPackageManager().getApplicationIcon(appInfo);
but then I need to update the widget with the icon, and RemoteViews only accept Bitmap.
Anyway to convert a Drawable to a Bitmap?
I've tried this but it didn't work
Bitmap bitmap = Bitmap.createBitmap(64,
64, Config.RGB_565);
Canvas c = new Canvas(bitmap);
d.draw(c);
I know it's possible since 开发者_Python百科I've seen apps in the market that do it.
Thanks.
found it: remoteViews.setImageViewBitmap(R.id.icon1, ((BitmapDrawable)d).getBitmap());
精彩评论