NotificationHelper

Centralized helper for managing Android local notifications.

This utility simplifies channel registration and notification posting while ensuring compliance with Android's notification requirements (API 26+ channels).

Note: Apps targeting API 33+ must declare and request the android.permission.POST_NOTIFICATIONS permission at runtime.

Initialization:

val notificationHelper = NotificationHelper(context)

notificationHelper.registerChannel(
NotificationChannelConfig(
id = "alerts",
name = "System Alerts"
)
)

Constructors

Link copied to clipboard
constructor(context: Context)

Functions

Link copied to clipboard

true si les notifications sont activées pour l'app.

Link copied to clipboard
fun cancel(id: Int)

Annule la notification identifiée par id.

Link copied to clipboard
fun cancelAll()

Annule toutes les notifications de l'app.

Link copied to clipboard
@RequiresPermission(value = "android.permission.POST_NOTIFICATIONS")
fun post(config: NotificationConfig)

Poste la notification décrite par config.

Link copied to clipboard

Registers a notification channel (idempotent — safe to call multiple times). This is a no-op on Android versions below API 26 (O).

Link copied to clipboard

Enregistre plusieurs canaux en une seule fois.