Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

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

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())
question from:https://stackoverflow.com/questions/65893516/why-do-notifications-on-oreo-not-display-unless-an-icon-is-set

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...