This project is an adaptation of the official Flutter Android Alarm Manager plugin.
It has been refactored to rely on flutter_service for Dart callbacks execution.
Please refer to flutter_service for details about what it does or bug reports.
The original implementation of android_alarm_manager
executes Dart callbacks in an Android JobIntentService
, which is a good default that will suit users most of the time.
However, there may be cases when you want the Dart callback to execute in a different context, like a Foreground Service for example. This is how this plugin differs from its original counterpart: it exposes the serviceType
you would like it to run the Dart callback in.
The original public API of the plugin remains available, but:
- the initialization is different.
- a new parameter
serviceType
is available in all available public methods.
Instead of calling
await AndroidAlarmManager.initialize();
You should now call
// at least one of the two should be set to true
await FlutterService.initialize(
jobIntentService: true,
foregroundService: true,
);
Most public methods available on the AndroidAlarmManager
class now expose an optional parameter serviceType
:
await AndroidAlarmManager.oneShot(
const Duration(seconds: 5),
1,
callback,
serviceType: 'JobIntentService' // by default set to 'JobIntentService' - currently also accepts 'ForegroundService'
);
If you have:
- initialized FlutterService with
foregroundService
set to true - started the FlutterService'
FlutterForegroundService
by broadcasting an Intent containing a notification
Then you may now decide to execute the Dart callback within that Foreground Service:
await AndroidAlarmManager.oneShot(
const Duration(seconds: 5),
1,
callback,
serviceType: 'ForegroundService' // by default set to 'JobIntentService' - currently also accepts 'ForegroundService'
);