Background Mode

Improve this doc

$ ionic plugin add cordova-plugin-background-mode
$ npm install --save @ionic-native/background-mode

Repo: https://github.com/katzer/cordova-plugin-background-mode

Cordova plugin to prevent the app from going to sleep while in background. Requires Cordova plugin: cordova-plugin-background-mode. For more info about plugin, vist: https://github.com/katzer/cordova-plugin-background-mode

Supported platforms

Usage

import { BackgroundMode } from '@ionic-native/background-mode';

constructor(private backgroundMode: BackgroundMode) { }

...

this.backgroundMode.enable();

Instance Members

enable()

Enable the background mode. Once called, prevents the app from being paused while in background.

disable()

Disable the background mode. Once the background mode has been disabled, the app will be paused when in background.

isEnabled()

Checks if background mode is enabled or not.

Returns: boolean returns a boolean that indicates if the background mode is enabled.

isActive()

Can be used to get the information if the background mode is active.

Returns: boolean returns a boolean that indicates if the background mode is active.

setDefaults(options)

Platforms:Android 

Override the default title, ticker and text. Available only for Android platform.

Param Type Details
options Configure

List of option to configure. See table below

configure(options)

Platforms:Android 

Modify the displayed information. Available only for Android platform.

Param Type Details
options Configure

Any options you want to update. See table below.

on(event)

Listen for events that the plugin fires. Available events are enable, disable, activate, deactivate and failure.

Param Type Details
event string

Event name

Returns: Observable<any>

moveToBackground()

Platforms:Android 

Android allows to programmatically move from foreground to background.

moveToForeground()

Platforms:Android 

Android allows to programmatically move from background to foreground.

overrideBackButton()

Platforms:Android 

Override the back button on Android to go to background instead of closing the app.

excludeFromTaskList()

Platforms:Android 

Exclude the app from the recent task list works on Android 5.0+.

isScreenOff()

Platforms:Android 

The method works async instead of isActive() or isEnabled().

wakeUp()

Platforms:Android 

Turn screen on

unlock()

Platforms:Android 

Turn screen on and show app even locked

BackgroundModeConfiguration

</tbody> </table>

Param Type Details
title String

Title of the background task

(optional)
text String

Description of background task

(optional)
icon string

This will look for .png in platforms/android/res/drawable|mipmap</p> (optional) </td> </tr>

color string (optional)
resume boolean

By default the app will come to foreground when taping on the notification. If false, plugin wont come to foreground when tapped.

(optional)
hidden boolean (optional)
bigText boolean (optional)
ticker String

The text that scrolls itself on statusbar

(optional)
silent boolean

if true plugin will not display a notification. Default is false.

(optional)

API

Native

General