简体   繁体   中英

Android: Firebase push notification different icon while app is on foreground and another while app is on background

How can I show same icon while app is on background or foreground? Below I have attached my screenshot

应用通知截图

I have used this app icon for my notification

通知图标

Thanks in advance!

Yes. This does happen. It can be fixed by setting color to the icon,when the notification is generated from inside the app.

 NotificationCompat.Builder(
 this,
 CHANNEL_ID
 )
.setSmallIcon(//your vector)
.setColor(ContextCompat.getColor(this, //color of the icon(mostly this may be 
the primary/secondary color that has been set ,according to the theme, in this 
case some hex of red)))

To keep it consistent, even for the notification generated in the background, a line can be written in the manifest:

<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/(your vector)” />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/(color of the icon)” />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM