android_alarm_manager 0.1.1

  • Example
  • Installing
  • Versions
  • 93


pub package

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:


Then in Dart code add:

import 'package:android_alarm_manager/android_alarm_manager.dart';

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

main() async {
  final int helloAlarmID = 0;
  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:

public FlutterNativeView createFlutterNativeView() {
  return AlarmService.getSharedFlutterView();

See the example's MainActivity to see an example.

If alarm callbacks will need access to other Flutter plugins, including the alarm manager plugin itself, it is necessary to teach the background service how to initialize plugins. This is done by giving the AlarmService a callback to call in the application's onCreate method. See the example's Application overrides. In particular, its Application class is as follows:

public class Application extends FlutterApplication implements PluginRegistrantCallback {
  public void onCreate() {

  public void registerWith(PluginRegistry registry) {

Which must be reflected in the application's AndroidManifest.xml. E.g.:


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

For help on editing plugin code, view the documentation.


  • Updated Gradle tooling to match Android Studio 3.1.2.


  • Breaking change. Set SDK constraints to match the Flutter beta release.


  • Simplified and upgraded Android project template to Android SDK 27.
  • Moved Android package to io.flutter.plugins.


  • Breaking change. Upgraded to Gradle 4.1 and Android Studio Gradle plugin 3.0.1. Older Flutter projects need to upgrade their Gradle setup as well in order to use this version of the plugin. Instructions can be found here.


  • Adds use of a Firebase plugin to the example. The example also now demonstrates overriding the Application's onCreate method so that the AlarmService can initialize plugin connections.


  • Add FLT prefix to iOS types.


  • Initial release.


// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:isolate';

import 'package:android_alarm_manager/android_alarm_manager.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/widgets.dart';

final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
FirebaseUser firebaseUser;

Future<Null> ensureFirebaseUser() async {
  if (firebaseUser == null) {
    firebaseUser = await firebaseAuth.currentUser();
    if (firebaseUser == null) {
      firebaseUser = await firebaseAuth.signInAnonymously();

class HelloMessage {
  final DateTime _now;
  final String _msg;
  final int _isolate;
  final FirebaseUser _user;
  final String _token;

  HelloMessage(this._now, this._msg, this._isolate, this._user, this._token);

  String toString() {
    return "[$_now] $_msg "
        "isolate=$_isolate "
        "user='$_user' "

void printHelloMessage(String msg) {
  ensureFirebaseUser().then((_) {
    firebaseUser.getIdToken().then((String idToken) {
      print(new HelloMessage(

void printHello() {
  printHelloMessage("Hello, world!");

void printGoodbye() {
  printHelloMessage("Goodbye, world!");

bool oneShotFired = false;

void printOneShot() {
  printHelloMessage("Hello, once!");

Future<Null> main() async {
  final int helloAlarmID = 0;
  final int goodbyeAlarmID = 1;
  final int oneShotID = 2;
  printHelloMessage("Hello, main()!");
  runApp(const Center(
      child: const Text('Hello, world!', textDirection: TextDirection.ltr)));
  await AndroidAlarmManager.periodic(
      const Duration(minutes: 1), helloAlarmID, printHello);
  await AndroidAlarmManager.periodic(
      const Duration(minutes: 1), goodbyeAlarmID, printGoodbye);
  if (!oneShotFired) {
    await AndroidAlarmManager.oneShot(
        const Duration(minutes: 1), oneShotID, printOneShot);

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  android_alarm_manager: "^0.1.1"

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

      import 'package:android_alarm_manager/android_alarm_manager.dart';
Version Uploaded Documentation Archive
0.1.1 Jun 1, 2018 Go to the documentation of android_alarm_manager 0.1.1 Download android_alarm_manager 0.1.1 archive
0.1.0 Mar 9, 2018 Go to the documentation of android_alarm_manager 0.1.0 Download android_alarm_manager 0.1.0 archive
0.0.5 Jan 17, 2018 Go to the documentation of android_alarm_manager 0.0.5 Download android_alarm_manager 0.0.5 archive
0.0.4 Dec 20, 2017 Go to the documentation of android_alarm_manager 0.0.4 Download android_alarm_manager 0.0.4 archive
0.0.2 Dec 3, 2017 Go to the documentation of android_alarm_manager 0.0.2 Download android_alarm_manager 0.0.2 archive


We analyzed this package on Jun 12, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.60.0
  • pana: 0.11.3
  • Flutter: 0.5.2


Describes how popular the package is relative to other packages. [more]
86 / 100
Code health derived from static analysis. [more]
100 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.


  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.6 1.14.10
meta 1.1.5
sky_engine 0.0.99
typed_data 1.1.5
vector_math 2.0.6 2.0.7