Wednesday, 1 March 2023

How to get consistent heads-up notification behaviour when phone is active?

I've got got the following notification. When receiving a notification while the phone is used, the OS will show a heads-up notification instead of the fullscreen intent. This looks all normal according to the documentation.

But if you swipe up the heads-up notification and receive a new notification right after. The behaviour looks inconsistant. Sometimes the notification opens the fullscreen intent although the phone is still active. Also in some cases i only hear the notification sound without heads-up or fullscreen intent. And sometimes a new heads-up notification is shown.

Is it possible to explain the different behaviour? Or fix it to be more constant (show heads-up when active and otherwise fullscreen intent)? It looks like it's related to the time in between the two notifications.

Implementation:

val notification = NotificationCompat.Builder(context, ALERT_NOTIFICATION_CHANNEL_ID)
    .setSmallIcon(R.drawable.ic_alert)
    .setContentTitle(context.getString(R.string.alert_notification_title))
    .setContentText(message)
    .setPriority(NotificationCompat.PRIORITY_HIGH)
    .setCategory(NotificationCompat.CATEGORY_ALARM)
    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
    .setSound(getDefaultNotificationSound(), AudioManager.STREAM_ALARM)
    .apply { if (fullscreen) setFullScreenIntent(alertNotificationPendingIntent, true) }
    .setContentIntent(contentPendingIntent)
    .setAutoCancel(true)
    .build()


from How to get consistent heads-up notification behaviour when phone is active?

No comments:

Post a Comment