
Facilitates native notification displays across Android, iOS, Web, and Desktop using JetBrains Compose. Features customizable notifications, event handling, and local notifications support with a unified API.
Native alerts, toasts, notifications and menus for Kotlin Multiplatform and Compose Multiplatform, with one API on Android, iOS, desktop and the web.
createNotification(NotificationType.ALERT).show("Your order is on its way", title = "Order placed")Add the dependency to commonMain:
// build.gradle.kts
kotlin {
sourceSets {
commonMain.dependencies {
implementation("io.github.khubaibkhan4:alert-kmp:2.1.0")
}
}
}Or with a version catalog:
[versions]
alertKmp = "2.1.0"
[libraries]
alert-kmp = { module = "io.github.khubaibkhan4:alert-kmp", version.ref = "alertKmp" }Alert-KMP 2.1.0 works with Kotlin 2.2 and newer. On Android it sets itself up through AndroidX Startup, so there is nothing to initialize.
import NotificationDuration
import NotificationType
import Notify
import createNotification
// A toast
createNotification(NotificationType.TOAST).show("Saved")
// An alert with a title
createNotification(NotificationType.ALERT).show("Your order is on its way", title = "Order placed")
// A system notification
createNotification(NotificationType.TOP).show("Your order has shipped", title = "Shop")
// A list of actions
createNotification(
NotificationType.MENU_CONTEXT(
listOf(
"Reply" to { reply() },
"Archive" to { archive() },
)
)
).show("Choose an action", title = "Message")
// The shortest way: a toast on Android, a short alert or system message elsewhere
Notify("Hello, World!", NotificationDuration.LONG)show() can be called from any thread.
| Type | Android | iOS | Desktop | Web |
|---|---|---|---|---|
TOAST |
Toast | Toast-style overlay | Message dialog | Toast at the bottom |
ALERT |
Alert dialog |
UIAlertController alert |
Message dialog | window.alert |
TOP |
System notification | Local notification | Small window | Banner at the top |
ICON_ALERT(iconName) |
Alert dialog with a drawable | Alert with an image | Message dialog | window.alert |
CUSTOM(title) |
Alert dialog with your title | Alert with your title | Window with your title | Box at the bottom right |
MENU_CONTEXT(actions) |
List dialog | Action sheet | Option dialog | Menu with buttons |
Every type works on every platform. Where a platform has no direct equivalent, Alert-KMP uses the closest native UI.
ALERT, ICON_ALERT, CUSTOM, MENU_CONTEXT) are shown on the Activity in front of the user. If no
Activity is in front (the app is in the background), the message is shown as a toast instead.TOP needs the notification permission on Android 13 and newer. Declare it and ask for it:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />TOP opens your app's notification settings.ICON_ALERT("ic_name") looks up a drawable by name in your app's resources.TOP asks for notification permission the first time, then schedules a local notification.| Alert | Menu | Toast | Top |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
| Alert | Menu | Toast |
|---|---|---|
![]() |
![]() |
![]() |
| Toast | Top and custom | Menu |
|---|---|---|
![]() |
![]() |
![]() |
sample shows every notification type on Android, iOS, desktop and the web, built from this repository's
source:
./gradlew :sample:androidApp:installDebug # Android
./gradlew :sample:shared:run # Desktop
./gradlew :sample:shared:wasmJsBrowserDevelopmentRun # Web
open sample/iosApp/iosApp.xcodeproj # iOS: run the iosApp schemeBadTokenException (#14). Dialogs use the Activity in front, and every
notification can be shown from any thread.showToast JavaScript
function.TOP or CUSTOM window no longer quits the app.IllegalArgumentException("Unsupported notification type"): every type works on every platform.Please follow the Code of Conduct.
Let's chat about potential projects, job opportunities, or any other collaboration! Feel free to connect with me through the following channels:
Native alerts, toasts, notifications and menus for Kotlin Multiplatform and Compose Multiplatform, with one API on Android, iOS, desktop and the web.
createNotification(NotificationType.ALERT).show("Your order is on its way", title = "Order placed")Add the dependency to commonMain:
// build.gradle.kts
kotlin {
sourceSets {
commonMain.dependencies {
implementation("io.github.khubaibkhan4:alert-kmp:2.1.0")
}
}
}Or with a version catalog:
[versions]
alertKmp = "2.1.0"
[libraries]
alert-kmp = { module = "io.github.khubaibkhan4:alert-kmp", version.ref = "alertKmp" }Alert-KMP 2.1.0 works with Kotlin 2.2 and newer. On Android it sets itself up through AndroidX Startup, so there is nothing to initialize.
import NotificationDuration
import NotificationType
import Notify
import createNotification
// A toast
createNotification(NotificationType.TOAST).show("Saved")
// An alert with a title
createNotification(NotificationType.ALERT).show("Your order is on its way", title = "Order placed")
// A system notification
createNotification(NotificationType.TOP).show("Your order has shipped", title = "Shop")
// A list of actions
createNotification(
NotificationType.MENU_CONTEXT(
listOf(
"Reply" to { reply() },
"Archive" to { archive() },
)
)
).show("Choose an action", title = "Message")
// The shortest way: a toast on Android, a short alert or system message elsewhere
Notify("Hello, World!", NotificationDuration.LONG)show() can be called from any thread.
| Type | Android | iOS | Desktop | Web |
|---|---|---|---|---|
TOAST |
Toast | Toast-style overlay | Message dialog | Toast at the bottom |
ALERT |
Alert dialog |
UIAlertController alert |
Message dialog | window.alert |
TOP |
System notification | Local notification | Small window | Banner at the top |
ICON_ALERT(iconName) |
Alert dialog with a drawable | Alert with an image | Message dialog | window.alert |
CUSTOM(title) |
Alert dialog with your title | Alert with your title | Window with your title | Box at the bottom right |
MENU_CONTEXT(actions) |
List dialog | Action sheet | Option dialog | Menu with buttons |
Every type works on every platform. Where a platform has no direct equivalent, Alert-KMP uses the closest native UI.
ALERT, ICON_ALERT, CUSTOM, MENU_CONTEXT) are shown on the Activity in front of the user. If no
Activity is in front (the app is in the background), the message is shown as a toast instead.TOP needs the notification permission on Android 13 and newer. Declare it and ask for it:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />TOP opens your app's notification settings.ICON_ALERT("ic_name") looks up a drawable by name in your app's resources.TOP asks for notification permission the first time, then schedules a local notification.| Alert | Menu | Toast | Top |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
| Alert | Menu | Toast |
|---|---|---|
![]() |
![]() |
![]() |
| Toast | Top and custom | Menu |
|---|---|---|
![]() |
![]() |
![]() |
sample shows every notification type on Android, iOS, desktop and the web, built from this repository's
source:
./gradlew :sample:androidApp:installDebug # Android
./gradlew :sample:shared:run # Desktop
./gradlew :sample:shared:wasmJsBrowserDevelopmentRun # Web
open sample/iosApp/iosApp.xcodeproj # iOS: run the iosApp schemeBadTokenException (#14). Dialogs use the Activity in front, and every
notification can be shown from any thread.showToast JavaScript
function.TOP or CUSTOM window no longer quits the app.IllegalArgumentException("Unsupported notification type"): every type works on every platform.Please follow the Code of Conduct.
Let's chat about potential projects, job opportunities, or any other collaboration! Feel free to connect with me through the following channels: