简体   繁体   English

Firebase 推送通知在后台应用程序时显示错误图标

[英]Firebase push notifications show wrong icon when app in background

I'm using Firebase push notifications in my app that come from a server.我在我的应用程序中使用来自服务器的 Firebase 推送通知。 When the app is in foreground, the correct notification icon is displayed.当应用程序处于前台时,会显示正确的通知图标。 But when the app is in background, there's a filled circle instead of the notification icon.但是当应用程序在后台时,会有一个实心圆圈而不是通知图标。

I have looked at similar issues, and I am using the correct values in my manifest.我已经查看了类似的问题,并且我在清单中使用了正确的值。 Here's what I have in my manifest:这是我的清单中的内容:

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

The notification color value seems to be working correctly.通知颜色值似乎工作正常。 The filled circle is that of my app's primary color, and if I change it to some random RGB value, it updates.实心圆圈是我的应用程序的原色,如果我将其更改为某个随机 RGB 值,它会更新。 But the notification icon is always a filled circle no matter what.但无论如何,通知图标始终是一个实心圆圈。

And here is how I'm handling my notifications when in foreground, but that works correctly:以下是我在前台处理通知的方式,但可以正常工作:

private fun showNotification(notification: RemoteMessage) {
    createNotificationChannel()

    val notificationId = notification.data["notificationId"]
    val feedItemId = notification.data["itemId"]
    val feedType = notification.data["type"]

    val intent = Intent(this, MainActivity::class.java).apply {
        flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
        putExtra(EXTRA_NOTIFICATION, true)
        putExtra(EXTRA_NOTIFICATION_ID, notificationId)
        putExtra(EXTRA_NOTIFICATION_FEED_ITEM_ID, feedItemId)
        putExtra(EXTRA_NOTIFICATION_FEED_TYPE, feedType)
    }

    val pendingIntent = PendingIntent.getActivity(this, (0..1000).random(), intent, PendingIntent.FLAG_ONE_SHOT)

    val builder = NotificationCompat.Builder(this, getString(R.string.notification_channel_id))
        .setSmallIcon(R.drawable.ic_stat_name)
        .setContentTitle(notification.notification?.title ?: "")
        .setContentText(notification.notification?.body ?: "")
        .setStyle(NotificationCompat.BigTextStyle()
            .bigText(notification.notification?.body ?: ""))
        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
        .setAutoCancel(true)
        .setContentIntent(pendingIntent)

    with(NotificationManagerCompat.from(this)) {
        notify(System.currentTimeMillis().toInt(), builder.build())
    }
}

So the notification icon is not the problem (as suggested in similar questions), as it displays correctly when the app is in foreground.所以通知图标不是问题(如类似问题中所建议的那样),因为当应用程序处于前台时它会正确显示。

I had this exact problem and for me what solved it was adding this to the AndroidManifest.xml .我遇到了这个确切的问题,对我来说解决的方法是将其添加到AndroidManifest.xml中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android 应用在后台无法处理 Firebase 推送通知 - Android app cannot handle Firebase push notifications when in background Android 12 firebase 当应用程序在后台时,推送通知不起作用 - Android 12 firebase push notifications don't work when app is in the background Flutter 推送通知应用程序后台:firebase_messaging - Flutter push notifications app background : firebase_messaging FCM 推送通知仅在应用程序处于后台时显示 - FCM Push Notifications are only displayed when app is in background 当应用程序处于后台或被杀死时,我想在 Android 中显示自定义 firebase 推送通知 state - I want to show a customize firebase push notification in Android when app is in background or killed state 应用程序在后台时推送通知不起作用 - Push notifications not working while app is in background SwiftUI Firebase 推送通知出现在应用内 - SwiftUI Firebase Push Notifications appear inside the app Firebase 当我更改我的应用程序包 ID 时,带有 Apple 推送通知的云消息传递停止工作 - Firebase Cloud Messaging with Apple push notifications stopped working when I changed my app Bundle ID Firebase 功能推送通知 - Firebase Funtions push notifications 通过 api 显示应用程序在后台时收到的 Firebase 消息通知 - Show Notification of Firebase Message onReceived when App is in Background Through api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM