MTK
MTK

Reputation: 13

Is it possible to create Alarm app that runs on post Oreo devices

In past we had Alarm Manager, Intent Services, Implicit broadcast receivers, that can run even when app is not in the background.

But today (post oreo) we have Work Manager & Job Schedulers. They do the stuff for us when the app is not in the background, but they don't guarantee about the exact time of execution.

So today if I need to create an app, where user can set an Alarm, which will be triggered at 5:00 am 27 September 2021 seems not possible. (Skip 2020 for obvious reasons ;) )

Has anyone tried creating Alarm app post oreo OS, I know Gmail and other system do this, but as far as I know they have special permission to perform thee operation, which are not allowed to other apps.

Upvotes: 0

Views: 62

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317750

AlarmManager is still valid for use on modern Android devices. The API documentation has a note about strict scheduling guarantees:

Note: Beginning with API 19 (Build.VERSION_CODES.KITKAT) alarm delivery is inexact: the OS will shift alarms in order to minimize wakeups and battery use. There are new APIs to support applications which need strict delivery guarantees; see setWindow(int, long, long, android.app.PendingIntent) and setExact(int, long, android.app.PendingIntent). Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested.

So, if you want to set an exact time to wake, you would use setExact() on API levels 19 and above.

Upvotes: 1

Related Questions