如何在Android中将位图设置为通知图标 [英] How to set bitmap as notification icon in Android
问题描述
您好,我正在寻找设置不在res
目录中的位图的方法.实际上,我是从URL获取该图标,并希望在通知区域中进行设置.
Hello I am looking for the way to set the bitmap which are not in res
directory. Actually I am getting that icon from the URL and want to set it in the notification area.
我在这里在做,但是只设置了res
目录中的图标.
Here I am doing but it is only set the icon which are in res
directory.
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_stat_logo)
.setContentTitle(Util.notificationTitle)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(notificationMessage))
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND)
.setContentText(notificationMessage);
是否有从URL设置获取位图并将该图标设置为Notification
图标的想法?
Any idea to set the fetch bitmap from URL and set that icon as Notification
icon ?
推荐答案
已在此处回答: https://stackoverflow.com/a/16055373/1071594
摘要:无法设置自定义的小图标,但是从API级别11开始,您可以使用 setLargeIcon(). html"rel =" nofollow noreferrer>位图.
Summary: It's not possible to set a custom small icon, but from API level 11 you can use setLargeIcon() after you have downloaded your image and converted it to a Bitmap.
[edit] There is another solution: If you create a completely custom notification with its own view, you could put anything inside that view, including downloaded images.
这篇关于如何在Android中将位图设置为通知图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!