Implementing Time-Sensitive Notifications
To ensure that time-sensitive notifications, such as countdown timers, progress bars, local scheduling, and snooze actions, update accurately and on time, your app must utilise Exact Alarms. Without these, the Android system may batch or delay notification updates to save battery, resulting in a broken user experience.
1. Declaration
First, you must declare the exact alarm permission in your AndroidManifest.xml. This allows the app to request precise wake-up windows from the system.
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
2. Handling Android Version Requirements
The behaviour of this permission changes depending on the user's API level. You must implement logic to handle these differences:
- Android 12 & 13 (API 31–33): The permission is typically granted upon installation if declared in the manifest. However, system battery optimizations can still interfere with background timing.
- Android 14+ (API 34+): This permission is denied by default for most apps. Even if declared in the manifest, you must manually check if the app has the capability at runtime.
3. Runtime Permission Check (Android 14+)
Since there is no standard system "Allow" dialog for exact alarms, you must guide the user to the system settings if the permission is missing.
Important Note
If
AlarmManager.canScheduleExactAlarms()returns false, you should display an educational UI (like a modal or snackbar) explaining that real-time updates require "Alarms & Reminders" access before navigating them to the settings page.
4. Quick Reference Summary
| Feature | Requirement |
|---|---|
| Primary Use Cases | Progress bars, Countdowns, Snooze, Scheduled local alerts. |
| Mechanism | AlarmManager using SCHEDULE_EXACT_ALARM. |
| Android 14+ Impact | Permission is restricted by default; requires user opt-in in Settings. |
| User Experience | Updates will drift or skip entirely if exact alarms are not enabled. |
Integration Checklist
- Add
<uses-permission>to manifest. - Implement
canScheduleExactAlarms()check for Android 12+. - Create a fallback UI/Dialog to redirect users to "Alarms & Reminders" settings on Android 14.
- Verifiy that notification background tasks are not being killed by battery optimization.
Updated about 2 hours ago
