开发者

How to show other applications icons on a widget?

开发者 https://www.devze.com 2023-03-18 02:45 出处:网络
I\'m trying to show some applications\' icons on an Android widget. I can get the icon as a drawable with:

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());

0

精彩评论

暂无评论...
验证码 换一张
取 消