Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/changjoo-park/flutter_foreground_service_plugin
https://github.com/changjoo-park/flutter_foreground_service_plugin
android flutter flutter-plugin foreground-service
Last synced: 17 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/changjoo-park/flutter_foreground_service_plugin
- Owner: ChangJoo-Park
- License: mit
- Created: 2019-11-08T09:39:05.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-03T06:36:08.000Z (over 1 year ago)
- Last Synced: 2024-06-19T02:02:00.776Z (5 months ago)
- Topics: android, flutter, flutter-plugin, foreground-service
- Language: Java
- Homepage:
- Size: 185 KB
- Stars: 40
- Watchers: 3
- Forks: 69
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# flutter_foreground_service_plugin
## You Can Do this plugin with..
- Start Foreground Service (with callback)
- Stop Foreground Service (with callback)
- Using infinite interval on your configurations
- Change Notification title and contents## You Can Not Do this plugin with...
- [ ] Change Notification Level
## If you use this plugin.
1. Add dependency to your pubspec.yaml
```yaml
dependencies:
...flutter_foreground_plugin: ^0.4.0
```2. Add permission for ForegroundService to AndroidManifest.xml
```xml
```
3. Add service for ForegroundService to AndroidManifest.xml below ``
```xml
```
4. Add use-sdk under `application`
```
```5. Add icon image for notification.
[Notification Icon Generator](https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type=clipart&source.clipart=ac_unit&source.space.trim=1&source.space.pad=0&name=ic_stat_ac_unit) will be helpful.
path: `android/app/src/main/res/drawable-*`
5. Write code for foreground service
```dart
void main() {
runApp(MyApp());
startForegroundService();// if you need to stop foreground service,
// await FlutterForegroundPlugin.stopForegroundService();
}void startForegroundService() async {
await FlutterForegroundPlugin.setServiceMethodInterval(seconds: 5);
await FlutterForegroundPlugin.setServiceMethod(globalForegroundService);
await FlutterForegroundPlugin.startForegroundService(
holdWakeLock: false,
onStarted: () {
print("Foreground on Started");
},
onStopped: () {
print("Foreground on Stopped");
},
title: "Flutter Foreground Service",
content: "This is Content",
iconName: "ic_stat_hot_tub",
);
}void globalForegroundService() {
debugPrint("current datetime is ${DateTime.now()}");
}
```