Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
cordova-plugin-advanced-background-mode
Advanced tools
Prevent apps from going to sleep in background.
This Plugin is a fork of this absolutely awesome Plugin by Katzer! Because it is unmainted, i decided to create this and keep it updated.
includeToTaskList
addedPlugin for the Cordova framework to perform infinite background execution.
Most mobile operating systems are multitasking capable, but most apps dont need to run while in background and not present for the user. Therefore they pause the app in background mode and resume the app before switching to foreground mode. The system keeps all network connections open while in background, but does not deliver the data until the app resumes.
Infinite background tasks are not official supported on most mobile operation systems and thus not compliant with public store vendors. A successful submssion isn't garanteed.
Use the plugin by your own risk!
The plugin can be installed via Cordova-CLI and is publicly available on NPM.
Execute from the projects root folder:
$ cordova plugin add cordova-plugin-advanced-background-mode
The plugin creates the object cordova.plugins.backgroundMode
and is accessible after the deviceready event has been fired.
It also includes an Ionic Wrapper
document.addEventListener('deviceready', function () {
// cordova.plugins.backgroundMode is now available
}, false);
<!-- Ionic Wrapper -->
import BackgroundMode from 'cordova-plugin-advanced-background-mode';
The plugin is not enabled by default. Once it has been enabled the mode becomes active if the app moves to background.
cordova.plugins.backgroundMode.enable();
// or
cordova.plugins.backgroundMode.setEnabled(true);
To disable the background mode:
cordova.plugins.backgroundMode.disable();
// or
cordova.plugins.backgroundMode.setEnabled(false);
Once the plugin has been enabled and the app has entered the background, the background mode becomes active.
cordova.plugins.backgroundMode.isActive(); // => boolean
A non-active mode means that the app is in foreground.
The plugin fires an event each time its status has been changed. These events are enable
, disable
, activate
, deactivate
and failure
.
cordova.plugins.backgroundMode.on('EVENT', function);
To remove an event listeners:
cordova.plugins.backgroundMode.un('EVENT', function);
Android allows to programmatically move from foreground to background or vice versa.
cordova.plugins.backgroundMode.moveToBackground();
// or
cordova.plugins.backgroundMode.moveToForeground();
Override the back button on Android to go to background instead of closing the app.
cordova.plugins.backgroundMode.overrideBackButton();
Exclude the app from the recent task list (works on Android 5.0+).
cordova.plugins.backgroundMode.excludeFromTaskList();
Include the app to the recent task list (works on Android 5.0+).
cordova.plugins.backgroundMode.includeToTaskList();
The method works async instead of isActive() or isEnabled().
cordova.plugins.backgroundMode.isScreenOff((bool) => {
...
});
A wake-up turns on the screen while unlocking moves the app to foreground even the device is locked.
// Turn screen on
cordova.plugins.backgroundMode.wakeUp();
// Turn screen on and show app even locked
cordova.plugins.backgroundMode.unlock();
To indicate that the app is executing tasks in background and being paused would disrupt the user, the plug-in has to create a notification while in background - like a download progress bar.
The title, text and icon for that notification can be customized as below. Also, by default the app will come to foreground when tapping on the notification. That can be changed by setting resume to false. On Android 5.0+, the color option will set the background color of the notification circle. Also on Android 5.0+, setting hidden to false will make the notification visible on lockscreen.
cordova.plugins.backgroundMode.setDefaults({
title: String,
text: String,
icon: 'icon' // this will look for icon.png in platforms/android/res/drawable|mipmap
color: String // hex format like 'F14F4D'
resume: Boolean,
hidden: Boolean,
bigText: Boolean
})
To modify the currently displayed notification
cordova.plugins.backgroundMode.configure({ ... });
Note: All properties are optional - only override the things you need to.
In silent mode the plugin will not display a notification - which is not the default. Be aware that Android recommends adding a notification otherwise the OS may pause the app.
cordova.plugins.backgroundMode.setDefaults({ silent: true });
Various APIs like playing media or tracking GPS position in background might not work while in background even the background mode is active. To fix such issues the plugin provides a method to disable most optimizations done by Android/CrossWalk.
cordova.plugins.backgroundMode.on('activate', function() {
cordova.plugins.backgroundMode.disableWebViewOptimizations();
});
Note: Calling the method led to increased resource and power consumption.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)This software is released under the Apache 2.0 License.
1.1.1
FAQs
Prevent apps from going to sleep in background.
The npm package cordova-plugin-advanced-background-mode receives a total of 0 weekly downloads. As such, cordova-plugin-advanced-background-mode popularity was classified as not popular.
We found that cordova-plugin-advanced-background-mode demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.