除非设置图标,否则为什么 Oreo 上的通知不显示

Why do notifications on Oreo not display unless an icon is set

这是平台错误还是我的实现有问题?它似乎与重要性级别无关。 Android 的版本是 8.1.0。 Target SDK 是 22(不幸的是我卡在了那个上面)。

            val defaultChannelId = AppConstants.NOTIFICATION_DEFAULT_ID
            val defaultChannelName = "New Orders - high priority"
            val defaultChannel = NotificationChannel(
                defaultChannelId,
                defaultChannelName,
                NotificationManager.IMPORTANCE_HIGH
            )

            defaultChannel.setSound(defaultSound, attributes)
            defaultChannel.description = "When a new order arrives"

            val notificationManager = NotificationManagerCompat.from(this)
            notificationManager.createNotificationChannel(defaultChannel)

点击按钮时:

出现通知:

val builder = NotificationCompat.Builder(requireContext(), AppConstants.NOTIFICATION_DEFAULT_ID).apply {
                        setContentTitle("New Order Received")
                        setContentText("Fetching order...$payload")
                        setSmallIcon(R.drawable.outline_receipt_white_24)
                        setSound(Uri.parse("android.resource://" + activity?.packageName + "/" + R.raw.notification_decorative))
                        setCategory(NotificationCompat.CATEGORY_STATUS)
                        priority = NotificationCompat.PRIORITY_HIGH
                        setProgress(0, 0, true)
                    }

val notificationManager = NotificationManagerCompat.from(requireContext())
notificationManager.notify(payload, builder.build())

通知没有出现:

val builder = NotificationCompat.Builder(requireContext(), AppConstants.NOTIFICATION_DEFAULT_ID).apply {
                        setContentTitle("New Order Received")
                        setContentText("Fetching order...$payload")
                        setSound(Uri.parse("android.resource://" + activity?.packageName + "/" + R.raw.notification_decorative))
                        setCategory(NotificationCompat.CATEGORY_STATUS)
                        priority = NotificationCompat.PRIORITY_HIGH
                        setProgress(0, 0, true)
                    }

val notificationManager = NotificationManagerCompat.from(requireContext())
notificationManager.notify(payload, builder.build())

Is this a platform bug or some problem in my implementation?

都不是,假设您是在暗示错误出在 Oreo 中。你总是应该提供一个小图标来显示在状态栏中。 Android 的旧版本中存在一个错误,您可以破解 Notification 使其不显示此类图标。恶意软件作者认为这 很棒 ,并且 Google 最终修复了它。