Skip to content

Commit 40ed929

Browse files
committed
Add permissions to manifest
1 parent a64d737 commit 40ed929

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ private void InjectAndroidManifest(string projectPath)
8383
AppendAndroidPermissionField(manifestPath, manifestDoc, "android.permission.RECEIVE_BOOT_COMPLETED");
8484
}
8585

86+
var exactScheduling = GetSetting<AndroidExactSchedulingOption>(settings, NotificationSettings.AndroidSettings.EXACT_ALARM);
87+
bool enableExact = (exactScheduling & AndroidExactSchedulingOption.ExactWhenAvailable) != 0;
88+
AppendAndroidMetadataField(manifestPath, manifestDoc, "com.unity.androidnotifications.exact_scheduling", enableExact ? "1" : "0");
89+
if (enableExact)
90+
{
91+
bool scheduleExact = (exactScheduling & AndroidExactSchedulingOption.AddScheduleExactPermission) != 0;
92+
bool useExact = (exactScheduling & AndroidExactSchedulingOption.AddUseExactAlarmPermission) != 0;
93+
// as documented here: https://developer.android.com/reference/android/Manifest.permission#USE_EXACT_ALARM
94+
// only one of these two attributes should be used or max sdk set so on any device it's one or the other
95+
if (scheduleExact)
96+
AppendAndroidPermissionField(manifestPath, manifestDoc, "android.permission.SCHEDULE_EXACT_ALARM", useExact ? "32" : null);
97+
if (useExact)
98+
AppendAndroidPermissionField(manifestPath, manifestDoc, "android.permission.USE_EXACT_ALARM");
99+
}
100+
86101
manifestDoc.Save(manifestPath);
87102
}
88103

0 commit comments

Comments
 (0)