Among the many features included in the Android operating system is the ability to set one or more alarms to ring at a date and time that you select. Android devices also allow you to set a custom alarm sound, which could be a traditional alarm sound, a ringtone or music stored on your device. Finally, the device enables you to choose whether the alarm repeats on one day or up to seven days a week. The ability to configure multiple alarms is useful if you need consistent alarm reminders at different times. Show
Alarms (based on the Alarms have these characteristics:
Note: For timing operations that are guaranteed to occur during the lifetime of your application, instead consider using the Set an inexact alarmWhen an app sets an inexact alarm, the system doesn't promise the delivery of the alarm at an exact point of time in the future. Instead, the system delivers this alarm at a time when it thinks it's most efficient for the device's battery. Inexact alarms provide some guarantees regarding the timing of alarm delivery, as long as no battery-saving restrictions such as Doze are in effect. The following sections describe these API guarantees. Deliver an alarm after a specific timeIf your app calls On Android 12 (API level 31) and higher, the system invokes the alarm within one hour of the supplied trigger time, unless any battery-saving restrictions are in effect such as battery saver or Doze. Deliver an alarm during a time windowIf your app calls If your app targets Android 12 or higher, the system can delay
the invocation of an inexact alarm by at least 10 minutes. For this reason, Deliver a repeating alarm at roughly regular intervalsIf your app calls
Set an exact alarmThe system invokes an exact alarm at a precise moment in the future. If your app targets Android 12 or higher, you must declare one of the "Alarms & reminders" permissions; otherwise, a Your app can set exact alarms using one of the following methods. These methods are ordered such that the ones closer to the bottom of the list serve more time-critical tasks but demand more system resources. setExact() Invoke an alarm at a nearly precise time in the future, as long as other battery-saving measures aren't in effect. Use this method to set exact alarms, unless your app's work is time-critical for the user. setExactAndAllowWhileIdle() Invoke an alarm at a nearly precise time in the future, even if battery-saving measures are in effect. setAlarmClock() Invoke an alarm at a precise time in the future. Because these alarms are highly visible to users, the system never adjusts their delivery time. The system identifies these alarms as the most critical ones and leaves low-power modes if necessary to deliver the alarms. System resource consumptionWhen the system triggers exact alarms that your app sets, the device consumes a great deal of resources, such as battery life, especially if it's in a power-saving mode. Furthermore, the system cannot easily batch these requests in order to use resources more efficiently. It's highly recommended that you create an
inexact alarm whenever possible. To perform longer work, schedule it using Declare the appropriate exact alarm permissionIf your app targets Android 12 or higher, you must obtain the "Alarms & reminders" special app access. To do so, declare the
<manifest ...> <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/> <application ...> ... </application> </manifest> If your app targets Android 13 (API level 33) or higher, you have the option to declare either the <manifest ...> <uses-permission android:name="android.permission.USE_EXACT_ALARM"/> <application ...> ... </application> </manifest> While both the
Acceptable use cases for USE_EXACT_ALARMThe following situations are considered acceptable uses of the
Using the SCHEDULE_EXACT_ALARM permissionUnlike To check whether the permission is granted to your app, call When the
Ask users to grant the |