plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[Question] Alarm Manager plus: OneShotAt not working as exact when the phone goes to doze mode

Open ShruAlekha opened this issue 3 years ago • 9 comments

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

ShruAlekha avatar Mar 10 '23 15:03 ShruAlekha

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.

vbuberen avatar Mar 13 '23 09:03 vbuberen

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.

ShruAlekha avatar Mar 13 '23 10:03 ShruAlekha

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 avatar Mar 15 '23 13:03 pete-cth

@pete-cth Thank you! That makes sense. The JobIntentService is unreliable in doze mode. #1149 is related to this issue.

ShruAlekha avatar Mar 16 '23 10:03 ShruAlekha

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

github-actions[bot] avatar Jun 15 '23 00:06 github-actions[bot]

I believe this is still a valid issue

pete-cth avatar Jun 15 '23 12:06 pete-cth

This is still an issue. Haven’t been able to resolve it.

shruthi-habu avatar Jun 15 '23 13:06 shruthi-habu

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

github-actions[bot] avatar Sep 15 '23 00:09 github-actions[bot]

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

github-actions[bot] avatar Dec 26 '23 00:12 github-actions[bot]