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: res/drawable/org_thebus_foregroundserviceplugin_notificationicon (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
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
Remove author from pubspec (deprecated)
Update example/readme to reflect Flutter 1.12.x changes
Add foreground service permission/service to manifest in plugin
Implemented FlutterPlugin interface for Flutter 1.12.x
Updated Kotlin to v1.3.50, Gradle to v3.5.3
Add option to get a wake lock
Either by passing true to second parameter of startForegroundService or by calling new method getWakeLock()
Should no longer crash due to @UiThread exception.
Add functions to check service started status & stop service
Slightly updated readme
Fix bug (class would try to init Instant regardless of api level)
Try to fix wording. ("No" got left behind on a separate line, so it look liked it said "iOS support planned" at a glance).
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.
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:
dependencies: foreground_service: ^1.1.0+2
2. Install it
You can install packages from the command line:
$ 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:
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]
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