Dil

AlarmManager.SetExact Method

Definition

Overloads

Name Description
SetExact(AlarmType, Int64, PendingIntent)

Schedule an alarm to be delivered precisely at the stated time.

SetExact(AlarmType, Int64, String, AlarmManager+IOnAlarmListener, Handler)

Direct callback version of setExact(int,long,PendingIntent).

SetExact(AlarmType, Int64, PendingIntent)

Schedule an alarm to be delivered precisely at the stated time.

[Android.Runtime.Register("setExact", "(IJLandroid/app/PendingIntent;)V", "GetSetExact_IJLandroid_app_PendingIntent_Handler")]
[Android.Runtime.RequiresPermission("android.permission.SCHEDULE_EXACT_ALARM")]
public virtual void SetExact(Android.App.AlarmType type, long triggerAtMillis, Android.App.PendingIntent operation);
[<Android.Runtime.Register("setExact", "(IJLandroid/app/PendingIntent;)V", "GetSetExact_IJLandroid_app_PendingIntent_Handler")>]
[<Android.Runtime.RequiresPermission("android.permission.SCHEDULE_EXACT_ALARM")>]
abstract member SetExact : Android.App.AlarmType * int64 * Android.App.PendingIntent -> unit
override this.SetExact : Android.App.AlarmType * int64 * Android.App.PendingIntent -> unit

Parameters

type
AlarmType

int: type of alarm. Value is one of the following: RTC_WAKEUP RTC ELAPSED_REALTIME_WAKEUP ELAPSED_REALTIME

triggerAtMillis
Int64

long: time in milliseconds that the alarm should go off, using the appropriate clock (depending on the alarm type).

operation
PendingIntent

PendingIntent: Action to perform when the alarm goes off; typically comes from IntentSender.getBroadcast(). This value cannot be null.

Attributes

Remarks

Schedule an alarm to be delivered precisely at the stated time. This method is like set(int,long,PendingIntent), but does not permit the OS to adjust the delivery time. The alarm will be delivered as nearly as possible to the requested trigger time. Note: only alarms for which there is a strong demand for exact-time delivery (such as an alarm clock ringing at the requested time) should be scheduled as exact. Applications are strongly discouraged from using exact alarms unnecessarily as they reduce the OS's ability to minimize battery use. Note: Starting with Build.VERSION_CODES.S, apps targeting SDK level 31 or higher need to request the SCHEDULE_EXACT_ALARM permission to use this API, unless the app is exempt from battery restrictions. The user and the system can revoke this permission via the special app access screen in Settings. Note: Exact alarms should only be used for user-facing features. For more details, see Exact alarm permission.

See also:

Android reference for android.app.AlarmManager.setExact.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

SetExact(AlarmType, Int64, String, AlarmManager+IOnAlarmListener, Handler)

Direct callback version of setExact(int,long,PendingIntent).

[Android.Runtime.Register("setExact", "(IJLjava/lang/String;Landroid/app/AlarmManager$OnAlarmListener;Landroid/os/Handler;)V", "GetSetExact_IJLjava_lang_String_Landroid_app_AlarmManager_OnAlarmListener_Landroid_os_Handler_Handler", ApiSince=24)]
public virtual void SetExact(Android.App.AlarmType type, long triggerAtMillis, string? tag, Android.App.AlarmManager.IOnAlarmListener listener, Android.OS.Handler? targetHandler);
[<Android.Runtime.Register("setExact", "(IJLjava/lang/String;Landroid/app/AlarmManager$OnAlarmListener;Landroid/os/Handler;)V", "GetSetExact_IJLjava_lang_String_Landroid_app_AlarmManager_OnAlarmListener_Landroid_os_Handler_Handler", ApiSince=24)>]
abstract member SetExact : Android.App.AlarmType * int64 * string * Android.App.AlarmManager.IOnAlarmListener * Android.OS.Handler -> unit
override this.SetExact : Android.App.AlarmType * int64 * string * Android.App.AlarmManager.IOnAlarmListener * Android.OS.Handler -> unit

Parameters

type
AlarmType

int: Value is one of the following: RTC_WAKEUP RTC ELAPSED_REALTIME_WAKEUP ELAPSED_REALTIME

triggerAtMillis
Int64

long

tag
String

String: This value may be null.

listener
AlarmManager.IOnAlarmListener

AlarmManager.OnAlarmListener: This value cannot be null.

targetHandler
Handler

Handler: This value may be null.

Attributes

Remarks

Direct callback version of setExact(int,long,PendingIntent). Rather than supplying a PendingIntent to be sent when the alarm time is reached, this variant supplies an OnAlarmListener instance that will be invoked at that time. Listener based alarms may be canceled by the Android system whenever the calling process no longer has any components running, such as Activity, Service, or ContentProvider, so only use these APIs when you do not need to receive alarms after the current component finishes, and also make sure to cancel(OnAlarmListener) them when it does. For example, if you use these APIs from an Activity, make sure to cancel the respective alarms when the activity finishes. If you need to receive the alarm even after that, use the PendingIntent based APIs. The OnAlarmListener's onAlarm() method will be invoked via the specified target Handler, or on the application's main looper if null is passed as the targetHandler parameter. On previous android versions Build.VERSION_CODES.S and Build.VERSION_CODES.TIRAMISU, apps targeting SDK level 31 or higher needed to hold the SCHEDULE_EXACT_ALARM permission to use this API, unless the app was exempt from battery restrictions. Note: Starting with android version Build.VERSION_CODES.UPSIDE_DOWN_CAKE, the system will explicitly drop any alarms set via this API when the calling app goes out of lifecycle.

Android reference for android.app.AlarmManager.setExact.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to