Home » Android » Android notification icon is a white circle

Android notification icon is a white circle

Posted by: admin June 15, 2020 Leave a comment

Questions:

I’ve got a strange problem with notification icon today.

It looks like this :
enter image description here
(the white circle …)

Did I do something bad ?

Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.icon_notification)
                .setContentTitle(this.getString(R.string.notification_title))
                .setContentText(this.getString(R.string.notification_text))
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

Here is my icon image (freshly downloaded from here https://material.io/icons/#ic_photo) :
http://image.noelshack.com/fichiers/2016/44/1478185219-icon-notification.png

Did I miss something ?

For the record, I’m using SDK 24 and only created the hdpi resource folder for now.

Edit #1 : I’ve added the ldpi, mdpi and xhdpi icons, nothing change …

Edit #2 : For more precision, I’m trying to create this notification from a service … FCM messaging service …

How to&Answers:

You must use a notification icon with no background. Android will add the circle background.

You can set background color with

.setColor(context.getResources().getColor(R.color.colorPrimary))

to match your app indentity.

Icon inside will remain white and circle will get the color you defined.

On Android Studio
On system bar
On notification

Answer:

If your compileSDKversion is above 20 then notification icon should be a white-on-transparent background image. Otherwise the image will be rendered as a white colored image.

Please go through the below link too for guidelines to create the icon

https://www.google.com/design/spec/patterns/notifications.html

and also the notification icon generator.

https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.space.trim=1&source.space.pad=0&name=ic_stat_example

Answer:

It seems to be a problem of cache during compilation … The first image I was using was bad (fully colored), so I think my compilator created somekind of cache on the filename.

I work on Windows and did this : uninstall the app from my phone, invalidate all cache from Android sudio => at re-compilation, the icon was OK.

Answer:

Note:- If device has android version above 20 you have to generate icon with transparent background and while generating notification use this snippet

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP){
        currentapiVersion=R.mipmap.ic_notification_lolipop;
} else{
        currentapiVersion=R.mipmap.ic_launcher;
}

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(currentapiVersion)......

Answer:

U need to have separate icon generated which will be white version of your launcher icon. U can use below link to generate such icon.

https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type=clipart&source.clipart=ac_unit&source.space.trim=1&source.space.pad=0&name=ic_stat_ac_unit

Note : You need to upload PNG image of your launcher icon with transparent background.

For setting icon u can have a method like this

private int getSmallIconForNotification(){
    return (Build.VERSION.SDK_INT>Build.VERSION_CODES.LOLLIPOP)? R.mipmap.ic_stat_launcher : R.mipmap.ic_launcher;
}

Code usage:

private NotificationCompat.Builder createNotificationBuilder(){
    return new NotificationCompat.Builder(this)
            .setSmallIcon(getSmallIconForNotification())
            .setContentTitle("New Message")
            .setContentText("Hi there.....")
            .setAutoCancel(true);
}