Alarmee is a Kotlin/Compose Multiplatform llibrary designed to simplify scheduling alarms and notifications on both Android and iOS platforms. With Alarmee, you can schedule one-time or repeating alarms and display platform-specific notifications seamlessly.
Be sure to show your support by starring βοΈ this repository, and feel free to contribute if you're interested!
- π One-off alarm: Schedule an alarm to trigger at a specific date and time.
- π Repeating alarm: Schedule recurring alarms with intervals: hourly, daily, weekly, monthly, yearly or custom (providing a duration).
- π Instant notifications: Push notifications immediately without scheduling them.
- π¨ Extensible Configuration: Customize alarms and notifications with platform-specific settings.
In your settings.gradle.kts
file, add Maven Central to your repositories:
repositories {
mavenCentral()
}
Then add Alarmee dependency to your module:
- With version catalog, open
libs.versions.toml
:
[versions]
alarmee = "1.5.0" // Check latest version
[libraries]
alarmee = { group = "io.github.tweener", name = "alarmee", version.ref = "alarmee" }
Then in your module build.gradle.kts
add:
dependencies {
implementation(libs.alarmee)
}
- Without version catalog, in your module
build.gradle.kts
add:
dependencies {
val alarmee_version = "1.5.0" // Check latest version
implementation("io.github.tweener:alarmee:$alarmee_version")
}
In the commonModule
, you need to use an instance of a subclass of AlarmeeScheduler
. Each platform will create the corresponding subclass of the AlarmeeScheduler
. This can be easily done with dependency injection.
π€ Android
In the androidMain
module, create a AlarmeeAndroidPlatformConfiguration(...)
instance with the following parameters:
val platformConfiguration: AlarmeePlatformConfiguration = AlarmeeAndroidPlatformConfiguration(
notificationIconResId = R.drawable.ic_notification,
notificationIconColor = androidx.compose.ui.graphics.Color.Red, // Defaults to Color.Transparent is not specified
notificationChannels = listOf(
AlarmeeNotificationChannel(
id = "dailyNewsChannelId",
name = "Daily news notifications",
importance = NotificationManager.IMPORTANCE_HIGH,
soundFilename = "notifications_sound",
),
AlarmeeNotificationChannel(
id = "breakingNewsChannelId",
name = "Breaking news notifications",
importance = NotificationManager.IMPORTANCE_LOW,
),
// List all the notification channels you need here
)
)
π iOS
In your iosMain
module, create a AlarmeeIosPlatformConfiguration
:
val platformConfiguration: AlarmeePlatformConfiguration = AlarmeeIosPlatformConfiguration
Important
Before using Alarmee, make sure the Notifications permission is granted on the target platform (Android official documentation, iOS official documentation).
Alternativally, you can use moko-permissions
to easily handle permissions for you.
Depending on your project configuration, you can create an instance of AlarmeeScheduler
in two different ways:
β‘οΈ Kotlin Multplatform (without Compose)
-
π€ Android
Create an instance of
AlarmeeSchedulerAndroid
with the configuration created previously:
val alarmeeScheduler: AlarmeeScheduler = AlarmeeSchedulerAndroid(context = context, platformConfiguration = platformConfiguration)
-
π iOS
Create an instance of
AlarmeeSchedulerIos
with the configuration created previously:
val alarmeeScheduler: AlarmeeScheduler = AlarmeeSchedulerIos(platformConfiguration = platformConfiguration)
β‘οΈ Compose Multplatform
Using rememberAlarmeeScheduler(...)
with the configuration created previously:
val alarmeeScheduler: AlarmeeScheduler = rememberAlarmeeScheduler(platformConfiguration = platformConfiguration)
You can schedule an alarm to be triggered at a specific time of the day, using Alarmee#schedule(...)
. When the alarm is triggered, a notification will be displayed.
For instance, to schedule an alarm on January 12th, 2025, at 5 PM:
alarmeeScheduler.schedule(
alarmee = Alarmee(
uuid = "myAlarmId",
notificationTitle = "π Congratulations! You've schedule an Alarmee!",
notificationBody = "This is the notification that will be displayed at the specified date and time.",
scheduledDateTime = LocalDateTime(year = 2025, month = Month.JANUARY, dayOfMonth = 12, hour = 17, minute = 0),
androidNotificationConfiguration = AndroidNotificationConfiguration( // Required configuration for Android target only (this parameter is ignored on iOS)
priority = AndroidNotificationPriority.HIGH,
channelId = "dailyNewsChannelId",
),
iosNotificationConfiguration = IosNotificationConfiguration(),
)
)
You can specify a RepeatInterval
parameter, which allows scheduling an alarm to repeat hourly, daily, weekly, monthly, yearly or custom, based on the specified scheduledDateTime.
You can use a fixed repeat interval to schedule an Alarmee every hour, day, week, month, or year.
For instance, to schedule an alarm to repeat every day at 9:30 AM, you can use RepeatInterval.Daily
:
alarmeeScheduler.schedule(
alarmee = Alarmee(
uuid = "myAlarmId",
notificationTitle = "π Congratulations! You've schedule a daily repeating Alarmee!",
notificationBody = "This notification will be displayed every day at 09:30.",
scheduledDateTime = LocalDateTime(year = 2025, month = Month.JANUARY, dayOfMonth = 12, hour = 9, minute = 30),
repeatInterval = RepeatInterval.Daily, // Will repeat every day
androidNotificationConfiguration = AndroidNotificationConfiguration( // Required configuration for Android target only (this parameter is ignored on iOS)
priority = AndroidNotificationPriority.DEFAULT,
channelId = "dailyNewsChannelId",
),
iosNotificationConfiguration = IosNotificationConfiguration(),
)
)
You can also set a custom repeat interval using RepeatInterval.Custom(duration)
to schedule an Alarmee at a specified duration interval.
For example, to schedule an alarm to repeat every 15 minutes, you can use RepeatInterval.Custom(duration = 15.minutes)
:
alarmeeScheduler.schedule(
alarmee = Alarmee(
uuid = "myAlarmId",
notificationTitle = "π Congratulations! You've schedule a custom repeating Alarmee!",
notificationBody = "This notification will be displayed every 15 minutes",
repeatInterval = RepeatInterval.Custom(duration = 15.minutes), // Will repeat every 15 minutes
androidNotificationConfiguration = AndroidNotificationConfiguration( // Required configuration for Android target only (this parameter is ignored on iOS)
priority = AndroidNotificationPriority.DEFAULT,
channelId = "otherChannelId",
),
iosNotificationConfiguration = IosNotificationConfiguration(),
)
)
An alarm can be cancelled using its uuid, using Alarmee#cancel(...)
. If an alarm with the specified uuid is found, it will be canceled, preventing any future notifications from being triggered for that alarm.
alarmeeScheduler.cancel(uuid = "myAlarmId")
You can push an alarm to instantly display a notification without scheduling it for a specific time:
alarmeeScheduler.push(
alarmee = Alarmee(
uuid = "myAlarmId",
notificationTitle = "π Congratulations! You've pushed an Alarmee right now!",
notificationBody = "This notification will be displayed right away",
androidNotificationConfiguration = AndroidNotificationConfiguration( // Required configuration for Android target only (this parameter is ignored on iOS)
priority = AndroidNotificationPriority.DEFAULT,
channelId = "immediateChannelId",
),
iosNotificationConfiguration = IosNotificationConfiguration(),
)
)
You can customize the notification sound on both Android and iOS.
Warning
Custom sounds must be under 30 seconds in length on both Android and iOS. If the sound exceeds this limit, the system will fall back to the default notification sound..
π€ Android
Notification sounds are set via AlarmeeNotificationChannel
, which allows you to define the sound file for a specific notification channel.
- Place your custom sound file in the
res/raw
directory of your app (e.g.,res/raw/notifications_sound.obb
). - Define a custom notification channel and provide the sound file name:
AlarmeeNotificationChannel(
id = "dailyNewsChannelId",
name = "Daily news notifications",
importance = NotificationManager.IMPORTANCE_HIGH,
soundFilename = "notifications_sound", // file name without the extension
)
π iOS
Notification sounds are set in the IosNotificationConfiguration
by providing the file name of the sound located in the app's bundle.
- Add your sound file to your Xcode project under the
main
bundle. - Reference the sound file with its exact name and extension:
Alarmee(
// ...
iosNotificationConfiguration = IosNotificationConfiguration(
soundFilename = "notifications_sound.wav",
),
)
π€ Android
- Global icon customization: You can set a default notification icon color and drawable for all notifications for your app.
AlarmeeAndroidPlatformConfiguration(
notificationIconResId = R.drawable.ic_notification,
notificationIconColor = Color.Yellow,
// ...
)
- Per-alarm icon customization: Override the global defaults by specifying the icon color and drawable for individual notifications.
alarmeeScheduler.schedule(
alarmee = Alarmee(
androidNotificationConfiguration = AndroidNotificationConfiguration(
notificationIconResId = R.drawable.ic_another_notification,
notificationIconColor = Color.Red,
// ...
),
// ...
)
)
π iOS
On iOS, customizing icon colors and drawables is not supported.
π€ Android
On Android, badge numbers are managed by the system and direct control over the badge number is not available in the notification API. The system automatically handles badge updates based on notifications.
π iOS
You can customize the badge number displayed on the app icon for notifications. This is done using the IosNotificationConfiguration
:
Alarmee(
// ...
iosNotificationConfiguration = IosNotificationConfiguration(
badge = 4,
),
)
If badge = 0
, the badge will be cleared from the app icon. If badge = null
, the badge will not be updated.
We love your input and welcome any contributions! Please read our contribution guidelines before submitting a pull request.
- Logo by Freeicons
Alarmee is licensed under the Apache-2.0.