From 9a265c534363779055c56d99484e7a2d70033c8e Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 24 Mar 2024 14:37:58 +0800 Subject: [PATCH] Ensure notifications can show on the top of old devices' home screen > On platforms O and above this value is ignored in favor of the values set on the notification's channel. On older platforms, this value is still used, so it is still required for apps supporting those platforms. See https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder#setDefaults(int). --- .../samples/socialite/repository/NotificationHelper.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/com/google/android/samples/socialite/repository/NotificationHelper.kt b/app/src/main/java/com/google/android/samples/socialite/repository/NotificationHelper.kt index a5d7bb68..01b443e1 100644 --- a/app/src/main/java/com/google/android/samples/socialite/repository/NotificationHelper.kt +++ b/app/src/main/java/com/google/android/samples/socialite/repository/NotificationHelper.kt @@ -267,6 +267,10 @@ class NotificationHelper @Inject constructor(@ApplicationContext context: Contex // notification. .setStyle(messagingStyle) .setWhen(messages.last().timestamp) + // Compat older APIs without notification channels for ensuring + // message notifications can show on the top of home screen. + .setPriority(NotificationCompat.PRIORITY_HIGH) + .setDefaults(Notification.DEFAULT_ALL) // Don't sound/vibrate if an update to an existing notification. if (update) { builder.setOnlyAlertOnce(true)