Sometimes scheduled notifications do not arrive or are late, may even not arrive at all until you open the app. Only was able to reproduce it with battery saving on.
Changes:
new flag for exact scheduling to add battery ignore permission to the manifest
new public APIs to query if using exact scheduling and if ignoring batter optimizations
new API to request exact scheduling (required on Android 12+ with SCHEDULE_EXACT permission)
new API to request app being excluded from battery saving
new API for notification permission rationale
Testing guide:
find devices to reproduce the issue on; likely you need Android 12 or later and battery to be put to one of more restrictive power saving options; make sure you disable exact scheduling in notification settings, best to schedule notification couple minutes in the future, kill app and lock device, best if notification does not show up at all until you launch app again; some devices need to be unplugged from computer to be truly in power saving mode;
there are two permissions for exact scheduling: SCHEDULE_EXACT_ALARM and USE_EXACT_ALARM. The later is Android 13 and should be enough for notifications to show up. The first one is since Android 12 and it allows app to request it, but you have control over it
requesting exact scheduling or batter ignore requires relevant permission, set the corresponding flag in notification settings
try requesting either exact scheduling or batter exempt (only one a the time, uninstall the app between tests or make sure settings are correct), I expect either to make notification arrive (but I'm not entirely sure, Samsung devices seem to be the most problematic here)
there are 3 new buttons in Main test project: two for making relevant requests and one for querying both;
test project on each focus gain prints notification permission status; only relevant on Android 13; if no permission given, it will print whether a UI with permission rationale should be shows (this is typically false initially and becomes true after permission was denied once).
Tested on:
Asus ROG (8.1)
Nokia 7 Plus (10)
Galaxy S22 (12)
Pixel 5 (13)
S22 was best for testing, as there with battery saving on inexact notifications didn't arrive at all until app is brought to foreground (at least withing reasonable amount time, didn't wait for hours).
Addresses: https://github.com/Unity-Technologies/com.unity.mobile.notifications/issues/231
Sometimes scheduled notifications do not arrive or are late, may even not arrive at all until you open the app. Only was able to reproduce it with battery saving on.
Changes:
Testing guide:
Tested on: