首页 > 解决方案 > Android Oreo GCM 推送通知图标白色,当应用程序关闭时

问题描述

我已经在 SO 以及其他一些谷歌搜索和文档页面上阅读了与此类似的 10 个类似问题,但我仍然无法弄清楚问题是什么。

基本上,如果应用程序关闭(或后台),推送通知图标显示为白色方块。

如果应用程序正在运行,它会显示我想要的图标。

我的图标是透明的,只是白色的。它是一个来自谷歌本身的简单图标。

这就是我所拥有的,以及问题可能出在哪里。我们的应用程序有多个模块。我将重点介绍其中的 3 个:

我正在PushNotification模块上构建本地通知:

override fun onMessageReceived(from: String?, data: Bundle?) {
    super.onMessageReceived(from, data)

    Log.d("PNReceiver", "onMessageReceived")

    val notification = data?.get("notification") as Bundle?
    val notificationTitle = notification?.get("title") as String
    val notificationBody = notification?.get("body") as String

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        val channelId = getString(R.string.notification_channel_id)
        if(manager.getNotificationChannel(channelId) == null) {
            val channel = NotificationChannel(channelId,
                    getString(R.string.notification_channel_name),
                    NotificationManager.IMPORTANCE_DEFAULT)
            channel.description =
                    getString(R.string.notification_channel_description)
            manager.createNotificationChannel(channel)
        }

        createLocalNotification(manager, channelId, notificationTitle, notificationBody)
    }
}

private fun createLocalNotification(notificationManager: NotificationManager,
                                    channelId: String,
                                    title: String,
                                    body: String) {

    val largeIcon = BitmapFactory.decodeResource(resources, R.drawable.ic_cake_variant)

    val builder = NotificationCompat.Builder(this, channelId)
            .setContentTitle(title)
            .setContentText(body)
            .setStyle(NotificationCompat.BigTextStyle().bigText(body))
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setSmallIcon(R.drawable.ic_cake_variant)
            .setLargeIcon(largeIcon)
            .setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_SOUND or Notification.DEFAULT_LIGHTS or Notification.DEFAULT_VIBRATE)


    notificationManager.notify(0, builder.build())
}

另外,我正在尝试在模块的清单上推送完全相同的图标PushNotification

<application>
... some gcm stuff...

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="@string/notification_channel_id" />

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

</application>

其他 2 个模块 (AppAppCode) 没有与推送通知代码相关的任何内容。

FWIW,我们的模块数据流/依赖图是App-> AppCode->PushNotification

此外,在版本上,我们仍在使用 GCM 而不是 FCMcom.google.android.gms:play-services-gcm:11.8.0

试过版本15.0.1,也没有成功。

我错过了一些非常明显的东西吗?谢谢您的帮助。

更新

收到的消息的正文如下所示:

Bundle[{
    google.sent_time = 1526919xxxxxx,
    google.message_id = 0: 1526919xxxxxxx % xxx c5e8a46xxxxxx,
    notification = Bundle[{
        body = test message 1,
        title = test title 1
    }],
    message = test message 1,
    collapse_key = com.mycompany
}]

此外,以下是我审查过的其他一些答案:

问题 1

问题2

问题 3

标签: androidpush-notificationgoogle-cloud-messagingandroid-push-notification

解决方案


推荐阅读