All Projects β†’ JulianAssmann β†’ flutter_background

JulianAssmann / flutter_background

Licence: MIT license
A flutter plugin to keep apps running in the background via foreground services. Currently Android only.

Programming Languages

dart
5743 projects
kotlin
9241 projects
HTML
75241 projects
ruby
36898 projects - #4 most used programming language
swift
15916 projects
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to flutter background

importar
R package to import/load packages or functions the 'Python' way
Stars: ✭ 17 (-70.69%)
Mutual labels:  package
SwiftPackage
πŸ† Template to make a Swift package
Stars: ✭ 37 (-36.21%)
Mutual labels:  package
meteor-graphql
Compiler plugin that supports GraphQL files in Meteor
Stars: ✭ 56 (-3.45%)
Mutual labels:  package
lint-deps
Lint for unused or missing dependencies in your node.js projects. Customize with plugins or configuration.
Stars: ✭ 48 (-17.24%)
Mutual labels:  package
hou packager
A simple SideFX Houdini package manager
Stars: ✭ 28 (-51.72%)
Mutual labels:  package
Dynamic-Parkour-System
Dynamic Parkour System is a FREE plugin for Unity that allows anyone to import any model and have an already working controller with parkour capabilities like in Assassin's Creed games.
Stars: ✭ 694 (+1096.55%)
Mutual labels:  package
timestampy
πŸ•’ Bunch of utilities useful when working with UNIX timestamps
Stars: ✭ 21 (-63.79%)
Mutual labels:  package
emacs-hacker-typer
A customizable implementation of http://hackertyper.com in emacs.
Stars: ✭ 21 (-63.79%)
Mutual labels:  package
ngp
New Go Package
Stars: ✭ 22 (-62.07%)
Mutual labels:  package
sidekiq-sequence
Sequential Sidekiq jobs for Rails
Stars: ✭ 38 (-34.48%)
Mutual labels:  background-jobs
get-bin-path
Get the current package's binary path
Stars: ✭ 25 (-56.9%)
Mutual labels:  package
repology-rules
Package normalization ruleset for Repology
Stars: ✭ 67 (+15.52%)
Mutual labels:  package
laravel-circuit-breaker
An implementation of the circuit breaker pattern for Laravel 5.6
Stars: ✭ 26 (-55.17%)
Mutual labels:  package
cross-post
Cross Post a blog to multiple websites
Stars: ✭ 66 (+13.79%)
Mutual labels:  package
golangflow
GolangFlow.io Website
Stars: ✭ 37 (-36.21%)
Mutual labels:  package
response
Response HTTP package for Simfony, Laravel, Lumen and PHP 7 with standard REST API
Stars: ✭ 14 (-75.86%)
Mutual labels:  package
telegram
πŸ“š Golang bindings for Telegram API
Stars: ✭ 15 (-74.14%)
Mutual labels:  package
parse it
A python library for parsing multiple types of config files, envvars & command line arguments that takes the headache out of setting app configurations.
Stars: ✭ 86 (+48.28%)
Mutual labels:  package
elm-generative
Making generative art in Elm
Stars: ✭ 23 (-60.34%)
Mutual labels:  package
FinMesh
A python package that brings together financial and economic data.
Stars: ✭ 20 (-65.52%)
Mutual labels:  package

flutter_background

"Buy Me A Coffee"

A plugin to keep flutter apps running in the background. Currently only works with Android.

It achieves this functionality by running an Android foreground service in combination with a partial wake lock and disabling battery optimizations in order to keep the flutter isolate running.

Note: This plugin currently only works with Android. PRs for iOS are very welcome, although I am not sure if a similiar effect can be achieved with iOS at all.

Getting started

To use this plugin, add flutter_background as a dependency in your pubspec.yaml file.

Android

Add the following permissions to the AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.julianassmann.flutter_background_example">

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

    <application>
    ...
    </application>
</manifest>

iOS

iOS is currently not supported.

Usage

Import flutter_background.dart:

import 'package:flutter_background/flutter_background.dart';

Initializing plugin and handling permissions

Before you can use this plugin, you need to initialize it by calling FlutterBackground.initialize(...):

final androidConfig = FlutterBackgroundAndroidConfig(
    notificationTitle: "flutter_background example app",
    notificationText: "Background notification for keeping the example app running in the background",
    notificationImportance: AndroidNotificationImportance.Default,
    notificationIcon: AndroidResource(name: 'background_icon', defType: 'drawable'), // Default is ic_launcher from folder mipmap
);
bool success = await FlutterBackground.initialize(androidConfig: androidConfig);

This ensures all permissions are granted and requests them if necessary. It also configures the foreground notification. The configuration above results in the foreground notification shown below when running FlutterBackground.enableBackgroundExecution().

The foreground notification created by the code above.

The arguments are:

  • notificationTitle: The title used for the foreground service notification.
  • notificationText: The body used for the foreground service notification.
  • notificationImportance: The importance of the foreground service notification.
  • notificationIcon: The icon used for the foreground service notification shown in the top left corner. This must be a drawable Android Resource (see here for more). E. g. if the icon with name "background_icon" is in the "drawable" resource folder, it should be of value `AndroidResource(name: 'background_icon', defType: 'drawable').
  • enableWifiLock: Indicates whether or not a WifiLock is acquired when background execution is started. This allows the application to keep the Wi-Fi radio awake, even when the user has not used the device in a while (e.g. for background network communications).

In this example, background_icon is a drawable resource in the drawable folders (see the example app). For more information check out the Android documentation for creating notification icons for more information how to create and store an icon.

In order to function correctly, this plugin needs a few permissions. FlutterBackground.initialize(...) will request permissions from the user if necessary. You can call initialize more than one time, so you can call initalize() every time before you call enableBackgroundExecution() (see below).

In order to notify the user about upcoming permission requests by the system, you need to know, whether or not the app already has these permissions. You can find out by calling

bool hasPermissions = await FlutterBackground.hasPermissions;

before calling FlutterBackground.initialize(...). If the app already has all necessary permissions, no permission requests will be displayed to the user.

Run app in background

With

bool success = await FlutterBackground.enableBackgroundExecution();

you can try to get the app running in the background. You must call FlutterBackground.initialize() before calling FlutterBackground.enableBackgroundExecution().

With

await FlutterBackground.disableBackgroundExecution();

you can stop the background execution of the app. You must call FlutterBackground.initialize() before calling FlutterBackground.disableBackgroundExecution().

To check whether background execution is currently enabled, use

bool enabled = FlutterBackground.isBackgroundExecutionEnabled;

Example

The example is a TCP chat app: It can connect to a TCP server and send and receive messages. The user is notified about incoming messages by notifications created with the plugin flutter_local_notifications.

Using this plugin, the example app can maintain the TCP connection with the server, receiving messages and creating notifications for the user even when in the background.

Maintainer

Julian Aßmann

If you experience any problems with this package, please create an issue on Github. Pull requests are also very welcome.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].