Background Mode

Improve this doc

$ ionic plugin add cordova-plugin-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';

BackgroundMode.enable();

Static 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.

onactivate()

Called when background mode is activated.

Returns: Observable<any> returns an observable that emits when background mode is activated

ondeactivate()

Called when background mode is deactivated.

Returns: Observable<any> returns an observable that emits when background mode is deactivated

onfailure()

Called when background mode fails

Returns: Observable<any> returns an observable that emits when background mode fails

BackgroundModeConfiguration

Param Type Details
title
(optional)
String

Title of the background task

ticker
(optional)
String

The text that scrolls itself on statusbar

text
(optional)
String

Description of background task

silent
(optional)
boolean

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

resume
(optional)
boolean

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

API

Native

General