Notification channels: Use NotificationChannelCompat.Builder.

This commit is contained in:
Benoit Marty 2024-06-19 10:53:20 +02:00
parent cfa5461b7d
commit 54740c982e
2 changed files with 24 additions and 30 deletions

View file

@ -16,8 +16,6 @@
package io.element.android.libraries.push.impl.notifications.channels package io.element.android.libraries.push.impl.notifications.channels
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context import android.content.Context
import android.media.AudioAttributes import android.media.AudioAttributes
import android.media.AudioManager import android.media.AudioManager
@ -121,49 +119,46 @@ class DefaultNotificationChannels @Inject constructor(
* intrude. * intrude.
*/ */
notificationManager.createNotificationChannel( notificationManager.createNotificationChannel(
NotificationChannel( NotificationChannelCompat.Builder(
NOISY_NOTIFICATION_CHANNEL_ID, NOISY_NOTIFICATION_CHANNEL_ID,
stringProvider.getString(R.string.notification_channel_noisy).ifEmpty { "Noisy notifications" }, NotificationManagerCompat.IMPORTANCE_DEFAULT
NotificationManager.IMPORTANCE_DEFAULT
) )
.apply { .setName(stringProvider.getString(R.string.notification_channel_noisy).ifEmpty { "Noisy notifications" })
description = stringProvider.getString(R.string.notification_channel_noisy) .setDescription(stringProvider.getString(R.string.notification_channel_noisy))
enableVibration(true) .setVibrationEnabled(true)
enableLights(true) .setLightsEnabled(true)
lightColor = accentColor .setLightColor(accentColor)
} .build()
) )
/** /**
* Low notification importance: shows everywhere, but is not intrusive. * Low notification importance: shows everywhere, but is not intrusive.
*/ */
notificationManager.createNotificationChannel( notificationManager.createNotificationChannel(
NotificationChannel( NotificationChannelCompat.Builder(
SILENT_NOTIFICATION_CHANNEL_ID, SILENT_NOTIFICATION_CHANNEL_ID,
stringProvider.getString(R.string.notification_channel_silent).ifEmpty { "Silent notifications" }, NotificationManagerCompat.IMPORTANCE_LOW
NotificationManager.IMPORTANCE_LOW
) )
.apply { .setName(stringProvider.getString(R.string.notification_channel_silent).ifEmpty { "Silent notifications" })
description = stringProvider.getString(R.string.notification_channel_silent) .setDescription(stringProvider.getString(R.string.notification_channel_silent))
setSound(null, null) .setSound(null, null)
enableLights(true) .setLightsEnabled(true)
lightColor = accentColor .setLightColor(accentColor)
} .build()
) )
// Register a channel for incoming and in progress call notifications with no ringing // Register a channel for incoming and in progress call notifications with no ringing
notificationManager.createNotificationChannel( notificationManager.createNotificationChannel(
NotificationChannel( NotificationChannelCompat.Builder(
CALL_NOTIFICATION_CHANNEL_ID, CALL_NOTIFICATION_CHANNEL_ID,
stringProvider.getString(R.string.notification_channel_call).ifEmpty { "Call" }, NotificationManagerCompat.IMPORTANCE_HIGH
NotificationManager.IMPORTANCE_HIGH
) )
.apply { .setName(stringProvider.getString(R.string.notification_channel_call).ifEmpty { "Call" })
description = stringProvider.getString(R.string.notification_channel_call) .setDescription(stringProvider.getString(R.string.notification_channel_call))
enableVibration(true) .setVibrationEnabled(true)
enableLights(true) .setLightsEnabled(true)
lightColor = accentColor .setLightColor(accentColor)
} .build()
) )
// Register a channel for incoming call notifications which will ring the device when received // Register a channel for incoming call notifications which will ring the device when received

View file

@ -43,7 +43,6 @@ class NotificationChannelsTest {
createNotificationChannels(notificationManager = notificationManager) createNotificationChannels(notificationManager = notificationManager)
verify { notificationManager.createNotificationChannel(any<NotificationChannelCompat>()) } verify { notificationManager.createNotificationChannel(any<NotificationChannelCompat>()) }
verify { notificationManager.createNotificationChannel(any<NotificationChannel>()) }
verify { notificationManager.deleteNotificationChannel(any<String>()) } verify { notificationManager.deleteNotificationChannel(any<String>()) }
} }