android_alarm_manager 0.4.1+6

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 95

android_alarm_manager #

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 within the <manifest></manifest> tags:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>

Next, within the <application></application> tags, add:

<service
    android:name="io.flutter.plugins.androidalarmmanager.AlarmService"
    android:permission="android.permission.BIND_JOB_SERVICE"
    android:exported="false"/>
<receiver
    android:name="io.flutter.plugins.androidalarmmanager.AlarmBroadcastReceiver"
    android:exported="false"/>
<receiver
    android:name="io.flutter.plugins.androidalarmmanager.RebootBroadcastReceiver"
    android:enabled="false">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"></action>
    </intent-filter>
</receiver>

Then in Dart code add:

import 'package:android_alarm_manager/android_alarm_manager.dart';

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

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

printHello will then run (roughly) every minute, even if the main app ends. However, printHello will not run in the same isolate as the main application. Unlike threads, isolates do not share memory and communication between isolates must be done via message passing (see more documentation on isolates here).

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 {
  @Override
  public void onCreate() {
    super.onCreate();
    AlarmService.setPluginRegistrant(this);
  }

  @Override
  public void registerWith(PluginRegistry registry) {
    GeneratedPluginRegistrant.registerWith(registry);
  }
}

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

    <application
        android:name=".Application"
        ...

Note: Not calling AlarmService.setPluginRegistrant will result in an exception being thrown when an alarm eventually fires.

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

For help on editing plugin code, view the documentation.

0.4.1+6 #

  • Bump the minimum Flutter version to 1.2.0.
  • Add template type parameter to invokeMethod calls.

0.4.1+5 #

  • Update AlarmService to throw a PluginRegistrantException if AlarmService.setPluginRegistrant has not been called to set a PluginRegistrantCallback. This improves the error message seen when the AlarmService.setPluginRegistrant call is omitted.

0.4.1+4 #

  • Updated example to remove dependency on Firebase.

0.4.1+3 #

  • Update README.md to include instructions for setting the WAKE_LOCK permission.
  • Updated example application to use the WAKE_LOCK permission.

0.4.1+2 #

  • Include a missing API dependency.

0.4.1+1 #

  • Log a more detailed warning at build time about the previous AndroidX migration.

0.4.1 #

  • Added support for setting alarms which persist across reboots.
    • Both AndroidAlarmManager.oneShot and AndroidAlarmManager.periodic have an optional rescheduleOnReboot parameter which specifies whether the new alarm should be rescheduled to run after a reboot (default: false). If set to false, the alarm will not survive a device reboot.

    • Requires AndroidManifest.xml to be updated to include the following entries:

      <!--Within the application tag body-->
      <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
      
      <!--Within the manifest tag body-->
      <receiver
          android:name="io.flutter.plugins.androidalarmmanager.RebootBroadcastReceiver"
          android:enabled="false">
          <intent-filter>
              <action android:name="android.intent.action.BOOT_COMPLETED"></action>
          </intent-filter>
      </receiver>
      
      

0.4.0 #

  • Breaking change. Migrated the underlying AlarmService to utilize a BroadcastReceiver with a JobIntentService instead of a Service to handle processing of alarms. This requires AndroidManifest.xml to be updated to include the following entries:

          <service
              android:name="io.flutter.plugins.androidalarmmanager.AlarmService"
              android:permission="android.permission.BIND_JOB_SERVICE"
              android:exported="false"/>
          <receiver
              android:name="io.flutter.plugins.androidalarmmanager.AlarmBroadcastReceiver"
              android:exported="false"/>
    
  • Fixed issue where background service was not starting due to background execution restrictions on Android 8+ (see issue #26846).

  • Fixed issue where alarm events were ignored when the background isolate was still initializing. Alarm events are now queued if the background isolate has not completed initializing and are processed once initialization is complete.

0.3.0 #

  • Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library.

0.2.3 #

  • Move firebase_auth from a dependency to a dev_dependency.

0.2.2 #

  • Update dependencies for example to point to published versions of firebase_auth.

0.2.1 #

  • Update dependencies for example to point to published versions of firebase_auth and google_sign_in.
  • Add missing dependency on firebase_auth.

0.2.0 #

  • Breaking change. A new isolate is always spawned for the background service instead of trying to share an existing isolate owned by the application.
  • Breaking change. Removed AlarmService.getSharedFlutterView.

0.1.1 #

  • Updated Gradle tooling to match Android Studio 3.1.2.

0.1.0 #

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

0.0.5 #

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

0.0.4 #

  • 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.

0.0.3 #

  • 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.

0.0.2 #

  • Add FLT prefix to iOS types.

0.0.1 #

  • Initial release.

example/README.md

android_alarm_manager_example #

Demonstrates how to use the android_alarm_manager plugin.

Getting Started #

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

Use this package as a library

1. Depend on it

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


dependencies:
  android_alarm_manager: ^0.4.1+6

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.4.1+6 Mar 30, 2019 Go to the documentation of android_alarm_manager 0.4.1+6 Download android_alarm_manager 0.4.1+6 archive
0.4.1+5 Mar 26, 2019 Go to the documentation of android_alarm_manager 0.4.1+5 Download android_alarm_manager 0.4.1+5 archive
0.4.1+4 Mar 22, 2019 Go to the documentation of android_alarm_manager 0.4.1+4 Download android_alarm_manager 0.4.1+4 archive
0.4.1+3 Feb 21, 2019 Go to the documentation of android_alarm_manager 0.4.1+3 Download android_alarm_manager 0.4.1+3 archive
0.4.1+2 Feb 14, 2019 Go to the documentation of android_alarm_manager 0.4.1+2 Download android_alarm_manager 0.4.1+2 archive
0.4.1+1 Feb 8, 2019 Go to the documentation of android_alarm_manager 0.4.1+1 Download android_alarm_manager 0.4.1+1 archive
0.4.1 Feb 5, 2019 Go to the documentation of android_alarm_manager 0.4.1 Download android_alarm_manager 0.4.1 archive
0.4.0 Jan 29, 2019 Go to the documentation of android_alarm_manager 0.4.0 Download android_alarm_manager 0.4.0 archive
0.3.0 Jan 25, 2019 Go to the documentation of android_alarm_manager 0.3.0 Download android_alarm_manager 0.3.0 archive
0.2.3 Dec 26, 2018 Go to the documentation of android_alarm_manager 0.2.3 Download android_alarm_manager 0.2.3 archive

All 17 versions...

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

We analyzed this package on Apr 24, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.4.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

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.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8