Skip to content

katzer/cordova-plugin-background-mode

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cordova Background Plugin - Sample App

Cordova plugin to prevent the app from going to sleep while in background, device get locked or screen goes off.

Instructions

Clone the example branch:

git clone -b example https://github.com/katzer/cordova-plugin-background-mode.git

And then execute:

cordova run [android|browser|ios|windows]

These will launch the simulator or any plugged in device and start the example application as seen below in the screenshots. It is also possible to open the project with Android Studio or Xcode.

A click on the Background enables the mode and starts them once the app is going into the background.

// 1) Request background execution
cordova.plugins.backgroundMode.enable();

// 2) Now the app runs ins background but stays awake
cordova.plugins.backgroundMode.on('activate', function () {
    setInterval(function () {
        cordova.plugins.notification.badge.increase();
    }, 1000);
});

// 3) App is back to foreground
cordova.plugins.backgroundMode.on('deactivate', function () {
    cordova.plugins.notification.badge.clear();
});

On Android a customizable notification will appear to inform the user that the app is performing a task in the background. It's possible to prevent any system notification by using the silent mode.

Customizable attributes are the title, text, ticker, icon and color:

cordova.plugins.backgroundMode.setDefaults({ color: 'FF0000' });

To use the silent mode:

cordova.plugins.backgroundMode.setDefaults({ silent: true });

Please read the plugin's README for further requirements and informations.

License

This software is released under the Apache 2.0 License.

Made with 😋 from Leipzig

© 2017 appPlant GmbH

Packages

No packages published

Contributors 24