foreground_service 1.1.0+2

foreground_service (Flutter v.1.12.x or later) #

Create Android foreground service/notification

Prep (Android side): #

Android foreground services require a notification to be displayed,
and notifications require an icon.

For this plugin to work, the icon needs to be in this specific location:


(take a look at the /example app if you're confused)

Use (Flutter/Dart side): #

To start the service, call ForegroundService.startForegroundService([serviceFunction])

serviceFunction will then be executed periodically, but "minimum/best-effort"
i.e. it will try to make the interval between function executions *at least* that long

Doesn't work? #

As long as you're calling ForegroundService.startForegroundService,
"flutter run" should show error messages that indicate what's wrong/missing

i.e. messages beginning with E/ForegroundServicePlugin indicate an error from the plugin

Caution: #

ForegroundService.notification.get* methods may give unexpected values.

Once notifications are sent out, there's no way to retrieve the "current" data.

To work around this, the plugin keeps a version of the notification around.
This version may not have been "sent out" yet, however.


Most of the fancy stuff is shamelessly pilfered from the android_alarm_manager plugin

1.1.0+2 #

Remove author from pubspec (deprecated)

1.1.0+1 #

Update example/readme to reflect Flutter 1.12.x changes

1.1.0 #

Add foreground service permission/service to manifest in plugin

1.0.0 #

Implemented FlutterPlugin interface for Flutter 1.12.x

0.3.1 #

Updated Kotlin to v1.3.50, Gradle to v3.5.3

0.3.0 #

Add option to get a wake lock

Either by passing true to second parameter of startForegroundService or by calling new method getWakeLock()

0.2.1 #

Should no longer crash due to @UiThread exception.

0.2.0 #

Add functions to check service started status & stop service

0.1.1+1 #

Slightly updated readme

0.1.1 #

Fix bug (class would try to init Instant regardless of api level)

0.1.0+2 #

Try to fix wording. ("No" got left behind on a separate line, so it look liked it said "iOS support planned" at a glance).

0.1.0+1 #


0.1.0 #

1st version. Should suffice to take care of the simple case/bare necessities: Change title, Change text, Change icon, Change priority, and most importantly run a dart function within the context of a foreground service.


foreground_service_example #

Demonstrates how to use the foreground_service plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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

  foreground_service: ^1.1.0+2

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:

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

We analyzed this package on Feb 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies