Skip to content

Commit 401c51b

Browse files
committed
Add setting for exact scheduling
1 parent d9a2d41 commit 401c51b

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
3+
namespace Unity.Notifications
4+
{
5+
/// <summary>
6+
/// Whether to schedule notifications at exact time or approximately (saves power).
7+
/// Exact scheduling is available in Android 6 (API 23) and newer, lower versions always use inexact scheduling.
8+
/// Android 12 (API 31) or newer requires SCHEDULE_EXACT_ALARM permission and grant from user to use exact scheduling.
9+
/// Android 13 (API 33) or newer can use USE_EXACT_ALARM permission to use exactscheduling without requesting users grant.
10+
/// </summary>
11+
[Flags]
12+
public enum AndroidExactSchedulingOption
13+
{
14+
/// <summary>
15+
/// Use exact scheduling when possible.
16+
/// </summary>
17+
ExactWhenAvailable = 1,
18+
19+
/// <summary>
20+
/// Add SCHEDULE_EXACT_ALARM permission to the manifest.
21+
/// </summary>
22+
AddScheduleExactPermission = 1 << 1,
23+
24+
/// <summary>
25+
/// Add USE_EXACT_ALARM permission to the manifest.
26+
/// </summary>
27+
AddUseExactAlarmPermission = 1 << 2,
28+
}
29+
}

com.unity.mobile.notifications/Editor/AndroidExactSchedulingOption.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.mobile.notifications/Editor/NotificationSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ private static T GetSettingValue<T>(BuildTargetGroup target, string key)
5050
public static class AndroidSettings
5151
{
5252
internal static readonly string RESCHEDULE_ON_RESTART = "UnityNotificationAndroidRescheduleOnDeviceRestart";
53+
internal static readonly string EXACT_ALARM = "UnityNotificationAndroidScheduleExactAlarms";
5354
internal static readonly string USE_CUSTOM_ACTIVITY = "UnityNotificationAndroidUseCustomActivity";
5455
internal static readonly string CUSTOM_ACTIVITY_CLASS = "UnityNotificationAndroidCustomActivityString";
5556

com.unity.mobile.notifications/Editor/NotificationSettingsManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ public static NotificationSettingsManager Initialize()
154154
"Reschedule on Device Restart",
155155
"Enable this to automatically reschedule all non-expired notifications after device restart. By default AndroidSettings removes all scheduled notifications after restarting.",
156156
settingsManager.GetOrAddNotificationSettingValue(NotificationSettings.AndroidSettings.RESCHEDULE_ON_RESTART, false, true)),
157+
new NotificationSetting(
158+
NotificationSettings.AndroidSettings.EXACT_ALARM,
159+
"Schedule at exact time",
160+
"Whether notifications should appear at exact time or approximate",
161+
settingsManager.GetOrAddNotificationSettingValue(NotificationSettings.AndroidSettings.EXACT_ALARM, (AndroidExactSchedulingOption)0, true)),
157162
new NotificationSetting(
158163
NotificationSettings.AndroidSettings.USE_CUSTOM_ACTIVITY,
159164
"Use Custom Activity",

com.unity.mobile.notifications/Editor/NotificationSettingsProvider.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ private int DrawSettingElements(Rect rect, BuildTargetGroup buildTarget, List<No
350350
if ((iOSAuthorizationOption)setting.Value == 0)
351351
setting.Value = (AuthorizationOption)(iOSAuthorizationOption.Badge | iOSAuthorizationOption.Sound | iOSAuthorizationOption.Alert);
352352
}
353+
else if (setting.Value.GetType() == typeof(AndroidExactSchedulingOption))
354+
{
355+
setting.Value = (AndroidExactSchedulingOption)EditorGUILayout.EnumFlagsField((AndroidExactSchedulingOption)setting.Value, dropdownStyle);
356+
}
353357
if (EditorGUI.EndChangeCheck())
354358
{
355359
m_SettingsManager.SaveSetting(setting, buildTarget);

0 commit comments

Comments
 (0)