0

At the outset, I already have gone through a couple of forums discussing this topic. As an example: Android Push Notifications: Icon not displaying in notification, white square shown instead

If I add the ic_launcher logo as the small icon to my notification, I see it on running the application. But, If I try to add a custom image (.png) file as the logo, I see an all white image.

What I do not understand is the concept of a transparent image/logo. This has been suggested as the cause of the blank image in many a forums. If this indeed is the case, then how to I go about generating a custom transparent image that can be displayed? It is to be noted that I am using the same image as my start up logo [inside manifest file] and it is working as expected.

My notification object is as follows:

notificationBuilder.setOngoing(true)
                .setSmallIcon(R.mipmap.ic_custom_image_icon)
                .setContentTitle("My-Title")
                .setPriority(NotificationManager.IMPORTANCE_MIN)
                .setCategory(Notification.CATEGORY_SERVICE)
                .setStyle(new NotificationCompat.DecoratedMediaCustomViewStyle()
                .setMediaSession(new MediaSessionCompat(this.getApplication(), MY_TAG).getSessionToken()))
                .setColor(0x169AB9)
                .setWhen(System.currentTimeMillis())
                .setOnlyAlertOnce(true)
                .setColorized(true);
mang4521
  • 300
  • 1
  • 12
  • hope this helps - I have a transparent image as my notification icon. I have my icon in the drawable directory and my builder looks as : notification.setContentTitle("Success") .setContentText("$projectDisplayName") .setSmallIcon(R.drawable.icon) .setColor(ContextCompat.getColor(context, R.color.logo_gold)) .setContentIntent(pendingIntent) .setProgress(0, 0, false) .setOngoing(false) .setAutoCancel(true) .build() – nt95 Sep 28 '20 at 13:43
  • @nt95 appreciate your response. My question is more on how do I go about generating a transparent icon. Let us say I have a .png image and would want this to behave as a transparent icon. How do I go about doing this? Is it that I need to convert a normal image to a transparent one or simply add the normal image into R.drawable and provide the notification params as you have presented above? – mang4521 Sep 28 '20 at 14:00
  • 1
    ah so you have an icon but you want to make it transparent is that correct? You can use online generators to convert the image into a transparent background. Eg, if you take the stack overflow icon, you could keep the grey and orange parts and remove the white background so the notification would only show the grey orange parts – nt95 Sep 28 '20 at 15:22
  • @nt95 got it. I browsed online for a way to convert a png file to a transparent background (eg: https://onlinepngtools.com/create-transparent-png) and it worked. Appreciate your help. – mang4521 Sep 28 '20 at 18:29

1 Answers1

0

As suspected, the custom image must have a transparent background. In order to achieve this, one can make use of online converters. Open the image with a transparent background as an Image Asset (under R.drawable) and the image is good for use as a small icon.

mang4521
  • 300
  • 1
  • 12