Skip to content

meticha/triggerx

TriggerX

triggerx-banner.png

Maven Central Jetpack Compose Supported Kotlin Version license Android Weekly GitHub stars License

TriggerX is a modular, developer-friendly alarm execution library for Android.

See the full documentation

It simplifies scheduling exact alarms and showing user-facing UIs at a specific time, even when your app has been killed or without you managing foreground-service boilerplate, wake-locks, or lock-screen flags.

Example

TriggerX Example


πŸ“Œ What does TriggerX do?

⏰ Exact alarms that work in Doze (API 25+) πŸ”“ Lock-screen activity automatically shown when the alarm fires
πŸ”‘ Handles permissions: exact alarm, battery optimisations, overlay, notification πŸ“± Wakes the device, starts a foreground service, then stops it
πŸ”„ Fetches fresh data at alarm time via suspend provider (Room, API, …) 🎨 Lets you build the UI in Jetpack Compose

Think of TriggerX as an execution layer that runs a piece of UI logic at the right time and hides the system details.


βœ… When should you use TriggerX?

πŸ“… You need to show a UI (reminder, alert, action screen) at a given time πŸ”„ The UI needs live data from DB, cache, or API
🧹 You want to avoid edge-case handling for Doze, foreground services, or flags 🎯 You want a consistent alarm solution across Android versions

πŸ“¦ Installation

Version catalogs
[versions]
triggerx = "latest-version"

[dependencies]
triggerx = { module = "com.meticha:triggerx", version.ref = "triggerx" }
Gradle DSL
dependencies {
    implementation("com.meticha:triggerx:latest-version")
}

πŸš€ Quick Start

0. Add these permission in your AndroidManifest.xml file:

<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

    <!-- Permissions for scheduling exact alarms -->
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

1. Initialize in your Application class

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        TriggerX.init(this) {

            /* UI that opens when the alarm fires */
            activityClass = MyAlarmActivity::class.java

            /* Foreground-service notification */
            useDefaultNotification(
                title = "Alarm running",
                message = "Tap to open",
                channelName = "Alarm Notifications"
            )

            /* Optional: Provide up-to-date data right before the UI opens */
            alarmDataProvider = object : TriggerXDataProvider {
                override suspend fun provideData(alarmId: Int, alarmType: String): Bundle {
                    return when (alarmType) {
                        "MEETING" -> {
                            val meeting = meetingRepository.getMeeting(alarmId)
                            return bundleOf(
                                "title" to meeting?.title,
                                "location" to meeting?.location
                            )
                        }

                        else -> bundleOf()
                    }
                }
            }
        }
    }
}

2. Ask for the permission

The library provides a composable helper to request permissions so that you don't have to manage this manually. However, the library provides the functionality to request permissions manually if you want to follow that path

@Composable
fun HomeScreen(
    viewModel: HomeViewModel = hiltViewModel()
) {
    val context = LocalContext.current
    val permissionState = rememberAppPermissionState()
    val coroutines = rememberCoroutineScope()

    Scaffold { paddingValues ->
        Column(
            modifier = Modifier
                .fillMaxSize()
                .padding(paddingValues)
                .padding(16.dp),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            ElevatedButton(
                onClick = {
                    coroutines.launch {
                        if (permissionState.allRequiredGranted()) {
                            viewModel.scheduleOneMinuteAlarm(context)
                        } else {
                            permissionState.requestPermission()
                        }
                    }
                }
            ) {
                Text("Schedule Activity")
            }
        }
    }
}

3. Schedule an alarm

val inFiveMinutes = Calendar.getInstance().apply {
    add(Calendar.MINUTE, 5)
}.timeInMillis


TriggerXAlarmScheduler().scheduleAlarm(
    context = this,
    alarmId = 1,
    type = "MEETING",
    triggerAtMillis = inFiveMinutes
)

πŸ’‘ You can schedule many alarms with different alarmId / alarmType.

🧩 Create your Alarm UI

class AppAlarmActivity : TriggerXActivity() {

    @Composable
    override fun AlarmContent() {
        val bundle = remember { intent?.getBundleExtra("ALARM_DATA") }
        val title = bundle?.getString("title") ?: "empty title"
        val location = bundle?.getString("location")
        Box(
            modifier = Modifier.fillMaxSize()
        ) {
            Column(
                modifier = Modifier
                    .fillMaxSize()
                    .background(
                        color = Color.White,
                        shape = RoundedCornerShape(32.dp)
                    )
                    .padding(32.dp),
                verticalArrangement = Arrangement.Center,
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                Icon(
                    imageVector = Icons.Default.Notifications,
                    contentDescription = "Trigger Icon",
                    tint = Color(0xFF111111),
                    modifier = Modifier.size(80.dp)
                )

                Spacer(modifier = Modifier.height(24.dp))

                Text(
                    text = title,
                    fontSize = 42.sp,
                    fontWeight = FontWeight.Bold,
                    color = Color(0xFF111111)
                )

                Spacer(modifier = Modifier.height(12.dp))

                Text(
                    text = location ?: "empty location",
                    fontSize = 20.sp,
                    fontWeight = FontWeight.Medium,
                    color = Color(0xFF333333),
                    textAlign = TextAlign.Center
                )
            }
        }
    }
}

What the base class handles for you:

  • πŸ”“ Shows over lock-screen
  • πŸ“± Turns screen on
  • βš™οΈ Chooses correct flags per Android version
  • πŸ“¦ Receives & parses Bundle (β€œALARM_DATA”)

πŸ” Permissions

TriggerX includes a Composable helper to request what it needs.

@Composable
fun HomeScreen(
    viewModel: HomeViewModel = hiltViewModel()
) {
    val context = LocalContext.current
    val permissionState = rememberAppPermissionState()
    val coroutines = rememberCoroutineScope()


    Scaffold { paddingValues ->
        Column(
            modifier = Modifier
                .fillMaxSize()
                .padding(paddingValues)
                .padding(16.dp),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            ElevatedButton(
                onClick = {
                    coroutines.launch {
                        if (permissionState.allRequiredGranted()) {
                            viewModel.scheduleOneMinuteAlarm(
                                context
                            )
                        } else {
                            permissionState.requestPermission()
                        }
                    }
                }
            ) {
                Text("Schedule Activity")
            }
        }
    }
}

Covered automatically:

Permission Version
⏰ Exact alarm API 31+
πŸ”‹ Ignore battery optimisation all
πŸ–Ό Overlay (only if needed) all
πŸ“’ Post-notification API 33+

🧠 How TriggerX works

  1. AlarmManager schedules an exact alarm
  2. BroadcastReceiver fires when alarm time arrives
  3. ForegroundService starts (Play-Store-compliant)
  4. Your AlarmDataProvider supplies fresh data (suspend)
  5. Service launches your activity with the data bundle
  6. ForegroundService stops; activity shows over lock-screen

πŸ—‚ Data Provider Interface

interface TriggerXDataProvider {
    /**
     * Fetch or build data for a specific alarm.
     * Called on a background dispatcher.
     */
    suspend fun provideData(alarmId: Int, alarmType: String): Bundle
}

Room example:

class RoomProvider(private val dao: MeetingDao) : TriggerXDataProvider {
    override suspend fun provideData(id: Int, type: String) = when (type) {
        "MEETING" -> dao.getMeeting(id)?.run {
            bundleOf("title" to title, "location" to location)
        } ?: Bundle.EMPTY
        else -> Bundle.EMPTY
    }
}

πŸ“ TriggerX Configuration Example

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        TriggerX.init(this) {
            notificationTitle = "Reminder"
            notificationMessage = "You have a scheduled event"
            notificationChannelName = "Event Alarms"
            customLogger = object : TriggerXLogger {
                override fun d(message: String) = Log.d("TriggerX", message)
                override fun e(message: String, throwable: Throwable?) =
                    Log.e("TriggerX", message, throwable)
            }
        }
    }
}

πŸ”— Retrofit or Network-Based Data Provider

class ApiProvider(private val api: AlarmApi) : TriggerXDataProvider {
    override suspend fun provideData(alarmId: Int, alarmType: String): Bundle {
        return try {
            val response = api.getAlarmDetails(alarmId)
            bundleOf("title" to response.title, "description" to response.description)
        } catch (e: Exception) {
            Bundle.EMPTY
        }
    }
}

πŸ’Ύ In-Memory or Static Data Provider

class StaticProvider : TriggerXDataProvider {
    override suspend fun provideData(alarmId: Int, alarmType: String): Bundle {
        return when (alarmType) {
            "WELCOME" -> bundleOf("title" to "Welcome!", "body" to "Thanks for installing our app.")
            else -> Bundle.EMPTY
        }
    }
}

πŸ” Delegating to Multiple Providers

class MultiSourceProvider(
    private val roomProvider: TriggerXDataProvider,
    private val networkProvider: TriggerXDataProvider
) : TriggerXDataProvider {

    override suspend fun provideData(alarmId: Int, alarmType: String): Bundle {
        return when (alarmType) {
            "MEETING" -> roomProvider.provideData(alarmId, alarmType)
            "NEWS" -> networkProvider.provideData(alarmId, alarmType)
            else -> Bundle.EMPTY
        }
    }
}

πŸ’Ύ Persistence

TriggerX stores minimal info (ID, type, activity class) in Preferences DataStore so alarms still work after the user swipes the app away.

πŸ—‘ Cancel alarms

TriggerXAlarmScheduler().cancelAlarm(this, alarmId = 1)

πŸ—¨ Troubleshooting

Issue Check
Alarm doesn’t fire Exact-alarm permission granted?
Activity not visible Overlay / lock-screen flags?
Service killed early Battery optimisation disabled?

🀝 Contributing

See CONTRIBUTING.MD for more info on how you can contribute to this repository

Find this repository useful? ❀️

Support it by joining stargazers for this repository. ⭐
Also follow Meticha for the next creations! 🀩

πŸ“„ License

Copyright 2025 Meticha

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Sponsor this project

 

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages