Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set bitmap as notification icon in Android

Tags:

android

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.

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

Any idea to set the fetch bitmap from URL and set that icon as Notification icon ?

like image 566
N Sharma Avatar asked Dec 03 '22 19:12

N Sharma


1 Answers

Already answered here: https://stackoverflow.com/a/16055373/1071594

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.

like image 105
Byte Welder Avatar answered Dec 21 '22 22:12

Byte Welder