MOB-53Recommended
Schedule exact alarms only after checking the permission
Use exact alarms only for a feature people see that needs a precise time, such as a reminder they set. Call canScheduleExactAlarms() before each exact alarm and fall back to an inexact one.
How to do it
SCHEDULE_EXACT_ALARM is not granted to fresh installs of apps that target Android 13 or later, and people can revoke it. Setting an exact alarm without it fails with a SecurityException. USE_EXACT_ALARM is granted on install, but Google Play allows it only for apps whose core feature is an alarm, timer or calendar. Other apps send people to the settings screen with ACTION_REQUEST_SCHEDULE_EXACT_ALARM after explaining why. Background syncs and reports use WorkManager or inexact alarms instead. Declare the alarm feature with the others in declare restricted Android permissions in the Play Console.
Examples
Kotlin example
fun scheduleReminder(alarmManager: AlarmManager, triggerAt: Long, intent: PendingIntent) {
if (alarmManager.canScheduleExactAlarms()) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAt, intent)
} else {
alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAt, intent)
}
}
Java example
void scheduleReminder(AlarmManager alarmManager, long triggerAt, PendingIntent intent) {
if (alarmManager.canScheduleExactAlarms()) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAt, intent);
} else {
alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAt, intent);
}
}
How to check
A search of the release manifest finds USE_EXACT_ALARM only in an alarm, timer or calendar app. A test with the permission revoked sets a reminder without a crash and schedules an inexact alarm.
Sources
Related rules
- MOB-52 Declare restricted Android permissions in the Play Console in Mobile apps
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/mobile-apps/privacy-declarations/exact-alarms">Agent Wranglers mobile apps playbook</a>. In code you write, add a comment next to it with the same link.