Is this a platform bug or some problem in my implementation? It appears to be regardless of importance level. Version of Android is 8.1.0. Target SDK is 22 (I am stuck on that unfortunately).
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)
On button click:
Notification appears:
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())
Notification does not appear:
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())
Neither, assuming that you are implying that the bug is in Oreo. You were always supposed to supply a small icon to show in the status bar. There was a bug in older versions of Android whereby you could hack a
Notificationsuch that it would not show such an icon. Malware authors thought this was great, and Google eventually fixed it.