[Question] Alarm Manager plus: OneShotAt not working as exact when the phone goes to doze mode
What is your question?
I have been using android_alarm_manager_plus plugin in my app that works as alarm clock. I am specifically using the oneShotAt endpoint and it works great until the phone goes to doze mode. When in doze mode, the callback is not exact. There is a delay of anywhere between 6-15 minutes based on the device. If I change the battery optimization for the app to not optimized, then it is exact. I have used the appropriate flags.
await AndroidAlarmManager.oneShotAt( scheduledTime, id, _oneShotTaskCallback, allowWhileIdle: true, exact: true, alarmClock: true, rescheduleOnReboot: true, wakeup: true, params: { "title": alarmTitle, "timeString": timeString, 'alarmTimeString': alarmTimeString });
The issue with changing battery optimization is that not all users understand and will not change it. Is there anything that I am missing here? Would really like to have the alarm callback be triggered at the exact time instead of the delay.
Checklist before submitting a question
- [X] I Google'd a solution and I couldn't find it
- [X] I searched on StackOverflow for a solution and I couldn't find it
- [X] I read the README.md file of the plugin
- [X] I am using the latest version of the plugin
- [X] All dependencies are up to date with
flutter pub upgrade - [X] I did a
flutter clean - [X] I tried running the example project
I would ask you to provide more information, starting from Android version and device and ending up more of your use cases. This way I would be able to answer your question better.
My app is on the play store and the issue is reported on Android 11 and 13 versions. I have tested it on these two versions using a motorola and samsung device and was able to reproduce the issue. The use case is using oneShotAt endpoint to trigger an alarm. I am testing it by setting the alarm and leaving the phone for a few hours unplugged, it gets to doze mode and I see the delay.
I am experiencing the same issue with this plugin.
If I set an alarm for 10 mins in the future using 'alarmClock: true'. Then unplug the phone, and turn the screen off, the alarm does not go off at the expected time.
I have previously raised the same issue against the flutter fire messaging plugin here. Which has since been fixed.
I suspect the issue is the use of the androidx.core.app.JobIntentService, which does not work as you might expect when in doze mode.
The fix used by the flutterfire plugin (and OneSignal and Telegram I believe) is to use a customized version of the JobIntentService. Here is a link to the two commits that fixed it for the flutter fire plugin.
@pete-cth Thank you! That makes sense. The JobIntentService is unreliable in doze mode. #1149 is related to this issue.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days
I believe this is still a valid issue
This is still an issue. Haven’t been able to resolve it.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days