flutter_foreground_plugin 0.5.0

Flutter Android

A foreground service plugin for Flutter. Support only Android (support Oreo). iOS not support yet.

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
dependencies:
    ...

  flutter_foreground_plugin: ^0.4.0
  1. Add permission for ForegroundService to AndroidManifest.xml
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
  1. Add service for ForegroundService to AndroidManifest.xml below </activity>
<service android:name="changjoopark.com.flutter_foreground_plugin.FlutterForegroundService"/>
  1. Add use-sdk under application
    <uses-sdk
        android:minSdkVersion="23"
        tools:overrideLibrary="changjoopark.com.flutter_foreground_plugin" />
  1. Add icon image for notification.

Notification Icon Generator will be helpful.

path: android/app/src/main/res/drawable-*

  1. Write code for foreground service
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()}");
}
16
likes
80
pub points
81%
popularity

A foreground service plugin for Flutter. Support only Android (support Oreo). iOS not support yet.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

pcjpcj2@gmail.com

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_foreground_plugin