1

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())
Daniel Wilson
  • 18,838
  • 12
  • 85
  • 135

1 Answers1

1

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

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 Notification such that it would not show such an icon. Malware authors thought this was great, and Google eventually fixed it.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    Thanks @CommonsWare I should have read the docs. You can see on https://developer.android.com/training/notify-user/build-notification it says `A small icon, set by setSmallIcon(). This is the only user-visible content that's required.` I think that should be in large red letters because unless you really want a notification to just make noise for some crazy reason, seems they are totally pointless without icons! – Daniel Wilson Jan 26 '21 at 12:16