Home > Net >  Does AlarmManager require battery optimization?
Does AlarmManager require battery optimization?

Time:04-03

I want to use AlarmManager at a specific time. Does AlarmManager require disable battery optimization? If yes how can I get this permission in android lollipop?

CodePudding user response:

You need to set the alarm with setExactAndAllowWhileIdle(). So long as you aren't setting them too often it will work. If you're setting it for every few minutes, you'll still have Doze issues (documentation says 1 alarm per 9 minutes max, but that will vary by version/device).

CodePudding user response:

AlarmManager is very hard to deal with, there is very hard to none chances that your alarm would trigger at a specified time because of all the restrictions by the Android system and the OEM's battery-saving apps.

Note from Android Doze mode documentation

Neither setAndAllowWhileIdle() nor setExactAndAllowWhileIdle() can fire alarms more than once per 9 minutes, per app.

You can ask your users to disable battery optimizations for your app to run correctly. To guide your users to disable battery optimizations you can use Don't kill my app and Autostarter libraries.

  • Related