Search code examples
androidiconsandroid-notifications

Android Notifications: Small icon not showing with custom image


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

Solution

  • 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.