foreground_service 0.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 83

foreground_service #

Create Android foreground service/notification

Prep (Android side): #

Step 1 - Create FlutterApplication subclass #
i.e. (Kotlin)

class OverrideApplication: FlutterApplication(), PluginRegistry.PluginRegistrantCallback{
    override fun onCreate() {

    override fun registerWith(p0: PluginRegistry?) {
Step 2 - Make necessary changes to android manifest #
Don't delete things willy-nilly unless you know what you're doing.
Just add lines/modify as necessary.

If you're having trouble, take a look at the /example app.

    <!-- add this line -->
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

    <!-- there should already be an <application/> section -->
    <!-- just modify the value of android:name, leave everything else -->
    <application android:name=".OverrideApplication">

        <!-- add this line within the application section -->
        <service android:name="org.thebus.foreground_service.ForegroundServicePlugin"
Step 3 #
Add icon resource to project.

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

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: ^0.3.0

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 Nov 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.


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.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies