GithubHelp home page GithubHelp logo

yang-dong-dong / flutter_foreground_service_plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from changjoo-park/flutter_foreground_service_plugin

0.0 0.0 0.0 189 KB

License: MIT License

Java 54.22% Ruby 14.02% Swift 4.07% Objective-C 1.84% Dart 25.85%

flutter_foreground_service_plugin's Introduction

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()}");
}

flutter_foreground_service_plugin's People

Contributors

andzejsw avatar cdfq152313 avatar changjoo-park avatar drobyshevalex avatar fabulousgee avatar yonatann avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.