Ionic Background Mode


Ionic Background Mode – This plugin is basically used to prevent the device’s sleep mode when app’s some background activity is going on, cordova-plugin-background-mode is used to set the background mode in Ionic. Here in this tutorial we are going to explain how you can install this plugin and use background mode.


Ionic Background Mode | Native Plugin Example

First let us see how to install the cordova plugin cordova-plugin-background-mode

Installation

You can install the cordova plugin simply as below –

Ionic Background Mode Native Plugin Example:

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

Example

Here is simple example of background mode-

Ionic Native Background Mode Example:

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

constructor(private backgroundMode: BackgroundMode) { }

...

this.backgroundMode.enable();

Instance Members

  • enable()– Enable Background Mode.
  • disable()– Disable Background Mode.
  • isEnabled()– Returns true if background mode enabled.
  • isActive()– Used to get information if background mode enabled.
  • setDefaults(options)– Override the default – text, title, ticker etc.
  • configure(options)– This is used to modify the default display information.
  • on(event)– This is used to listen the events that are fired by plugin.
  • moveToBackground()– Move Forground to background.
  • disableWebViewOptimizations()– Enable GPS tracking view in background.
  • moveToForeground()– Move Background to forground.
  • overrideBackButton()– Override the default back button.
  • excludeFromTaskList()– Exclude app from recent task lists.
  • isScreenOff() This works as async instead of isActive or isEnabled.
  • wakeUp()– Turn on screen.
  • unlock()– Turn on screen and show app although screen is locked.

Advertisements

Add Comment

📖 Read More