@ThreadSafe public final class AlarmManagerCompat extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
AlarmManagerCompat.AlarmToken
Effectively immutable class representing a token used to set an alarm.
|
static interface |
AlarmManagerCompat.AlarmType
Defines the possible values for the alarm manager type.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel(AlarmManagerCompat.AlarmToken alarmToken)
Cancels the alarm, on a best-effort basis.
|
static AlarmManagerCompat |
getInstance(Context applicationContext) |
AlarmManagerCompat.AlarmToken |
setExact(Context context,
int type,
long triggerAtMillis,
PendingIntent pendingIntent,
long currentWalltimeMillis,
long currentElapsedRealtimeMillis)
This method schedules exact alarms with support for the new exact alarm behavior KitKat,
works around the minimum alarm interval of 5 seconds for Lollipop, and provides best-effort
workarounds for the idling behavior of Marshmallow.
|
public static AlarmManagerCompat getInstance(Context applicationContext)
applicationContext - Application context.public AlarmManagerCompat.AlarmToken setExact(Context context, int type, long triggerAtMillis, PendingIntent pendingIntent, long currentWalltimeMillis, long currentElapsedRealtimeMillis)
currentWalltimeMillis and currentElapsedRealtimeMillis passed in. For a
short duration RTC alarm, there is a risk of TOCTOU errors if the wall time changes after
this method is called. To mitigate this, clients should be able to handle receiving a short
duration RTC alarm slightly sooner or later than expected. This risk does not apply to
longer-duration alarms.context - Application context.type - One of the alarm types: AlarmManager.RTC, AlarmManager.RTC_WAKEUP
, AlarmManager.ELAPSED_REALTIME, or
AlarmManager.ELAPSED_REALTIME_WAKEUP.triggerAtMillis - Time in milliseconds when the alarm should fire. This will be either
wall time or elapsed realtime, depending on type.pendingIntent - Operation to execute when the alarm fires. This object should not
be mutated after being passed to this method.public void cancel(AlarmManagerCompat.AlarmToken alarmToken)