PoulsQ
PoulsQ

Reputation: 2016

Android notification icon is a white circle

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

Upvotes: 16

Views: 20709

Answers (6)

mage1k99
mage1k99

Reputation: 131

I had the same problem while the app is closed and this helped me

Unfortunately this was a limitation of Firebase Notifications in SDK 9.0.0-9.6.1. When the app is in the background the launcher icon is use from the manifest (with the requisite Android tinting) for messages sent from the console.

With SDK 9.8.0 however, you can override the default! In your AndroidManifest.xml you can set the following fields to customize the icon and color:

<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/notification_icon" />
<meta-data android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/google_blue" />

Upvotes: 3

Amit Tumkur
Amit Tumkur

Reputation: 2835

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

Upvotes: 1

Bhavnik
Bhavnik

Reputation: 2048

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

Upvotes: 0

Ajith K P
Ajith K P

Reputation: 396

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

Upvotes: 9

PoulsQ
PoulsQ

Reputation: 2016

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.

Upvotes: 3

inlacou
inlacou

Reputation: 166

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

Upvotes: 7

Related Questions