android_alarm_manager 0.0.2 copy "android_alarm_manager: ^0.0.2" to clipboard
android_alarm_manager: ^0.0.2 copied to clipboard

discontinued
outdatedDart 1 only

A plugin for using the AlarmManager on Android.

android_alarm_manager #

A Flutter plugin for accessing the Android AlarmManager service, and running Dart code in the background when alarms fire.

Getting Started #

After importing this plugin to your project as usual, add the following to your AndroidManifest.xml:

<service
    android:name="io.flutter.androidalarmmanager.AlarmService"
    android:exported="false"/>

Then in Dart code add:

import 'package:android_alarm_manager/android_alarm_manager.dart';

void printHello() {
  final DateTime now = new DateTime.now();
  final int isolateId = Isolate.current.hashCode;
  print("[$now] Hello, world! isolate=${isolateId} function='$printHello'");
}

main() async {
  final int helloAlarmID = 0;
  runApp(...);
  await AndroidAlarmManager.periodic(const Duration(minutes: 1), helloAlarmID, printHello);
}

printHello will then run (roughly) every minute, even if the main app ends. If possible it will reuse the same Dart Isolate from the application's main activity. Additionally, if you would like a new main activity of your application to reuse the Isolate from an existing background service created by this plugin, add the following override to your app's MainActivity class:

@Override
public FlutterNativeView createFlutterNativeView() {
  return AlarmService.getSharedFlutterView();
}

See the example's MainActivity to see an example.

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.