HeadsUp Notification not displayed on KitKat

蓝咒 提交于 2019-12-11 12:24:51

问题


I have a notification, presented using the following code:

    // Create the notification
    android.app.Notification systemNotification = new NotificationCompat.Builder(context)
            // Set notification data and appearance
            .setContentTitle(notification.getNotificationLabel())
            .setContentText(notification.getMessage())
            .setSmallIcon(notification.getNotificationDrawable())
            .setWhen(new Date().getTime())

            // Set notification options
            .setCategory(NotificationCompat.CATEGORY_MESSAGE)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setDefaults(NotificationCompat.DEFAULT_ALL)
            .build()
    ;

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(notification.getNotificationId(), systemNotification);

When run on Lollypop and newer, it works fine and the notification appears both in the status bar and as a popup notification as expected/desired. On Kitkat, the notification only appears in the status bar, there's no popup notification. I can still open the notification from the status bar and everything looks and works fine, it's just the popup notification that's missing.

Some of the things I've tried so far:

  • different options to setDefaults
  • different options to setPriority
  • verified that notifications are on in the system settings panel for the application

回答1:


On Kitkat, the notification only appears in the status bar, there's no popup notification

That is because the heads-up notification behavior was added in Android 5.0 and did not exist in prior versions of Android.




回答2:


Ensure that you have popup notifications enabled on your KitKat device.



来源:https://stackoverflow.com/questions/37257698/headsup-notification-not-displayed-on-kitkat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!