SAMPLE APP
Plugin 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-background-mode
Or install a specific version:
$ cordova plugin add de.appplant.cordova.plugin.background-mode@VERSION
Or install the latest head version:
$ cordova plugin add https://github.com/katzer/cordova-plugin-background-mode.git
Or install from local source:
$ cordova plugin add cordova-plugin-background-mode --searchpath <path>
The plugin creates the object cordova.plugins.backgroundMode
and is accessible after the deviceready event has been fired.
document.addEventListener('deviceready', function () {
// cordova.plugins.backgroundMode is now available
}, false);
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();
The method works async instead of isActive() or isEnabled().
cordova.plugins.backgroundMode.isScreenOff(function(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.
Made with
? 2017 appPlant GmbH & meshfields
Cordova(后台模式)Background Mode 记录用 (转)https://www.jianshu.com/p/6ebf9d0bf648 Background Mode Cordova插件,以防止应用程序在后台进入睡眠状态。 需要Cordova插件:cordova-plugin-background-mode。 有关插件的更多信息: https://github.com/katzer/
最近在开发部门的一个APP,需要有消息推送功能,前端用轮询,一开始用了cordova-plugin-background-mode插件使其可以后台运行,但是用这个插件太耗电了,也没找到解决方法。后来想到可以在手机屏幕解锁时进行查询,又了解到这种监听属于广播,于是就用到了今天要讲的cordova-broadcaster广播插件。 cordova-broadcaster插件官网 怎么添加cordova
PDF 在线查阅 ios 通过 cordova-plugin-inappbrowser cordova.InAppBrowser.open(url, '_blank', 'location=no') android 通过 vue-pdf <van-pdf :src="url" :page="currentPage" @progress="load = $event" @num-pages="nu
目标:写一个可以让别人通过命令安装的android平台的cordova插件 步骤: 1、准备一个cordova项目导入到eclipse中(为了方便安装插件可以把cordova项目中的platform做为eclipse的工作空间,如果不懂可以看这里 点击打开链接 ) 一、创建空白的cordova项目 1、到你想创建项目的目录下,打开黑窗口 cordova create hellocom.exam
问 题 In my Ionic 2 app (TypeScript), where I use plugins, for example the Camera plugin from ionic-native which works fine. Now I want to use BackgroundMode plugin:https://github.com/katzer/cordova-plu
cordova的webview环境下,ios和Android的兼容性差异整理 好像都是ios的锅。? 1、ios上下有2个黑色块 解决方案: 添加启动屏 1cordova plugin add cordova-plugin-splashscreen 复制代码 1<!-- config.xml --> 2<platform name="ios"> 3 <splash height="1136"
百度地图定位Cordova插件,支持Android,IOS 可以在此地址查看example 基于百度地图Android版定位SDK(v7.1)以及百度地图IOS SDK (v3.2.1) 一,申请Android及IOS版密钥 申请密钥Android定位SDK 每一个AndroidManifest.xml 中的package属性 对应一个AK,不可混用 iOS SDK开发密钥 每一个Bundle I
PayPal-Cordova-Plugin 正如名字介绍的那样,它是 PayPal SDK Cordova/Phonegap 插件。它能够在 Cordova/Phonegap 平台上方便的使用 iOS 和安卓系统上的本地 SDKs。但使用它的时候必须下载 PayPal Mobile SDK 库。
IOS生成失败,出现以下错误 安装“Cordova-plugin-photo-library”失败:“Cordovaerror:安装的插件版本:”Cordova-plugin-file@6.0.1“不满足依赖插件要求”Cordova-plugin-file@^4.3.2'“。尝试--强制使用已安装的插件作为依赖项。 Cli封装ionic/CLI-UTILS:1.19.1 ionic(ionic C
我已经在我的ionic/cordova项目上下载并安装了PayPal-Cordova-Plugin。 当我尝试构建项目时,我会遇到以下错误: 我把它改成了我认为应该有的: 但仍然会发生同样的错误。
动态设置窗口的背景等. 支持 安装 $ npm install universal-background --save 方法 setColor(options) 动态设置窗口的背景色。 参数 属性 类型 默认值 必选 描述 支持 color String x 窗口的背景色 topColor String x 顶部窗口的背景色,仅 iOS 支持 bottomColor String x 底部窗口的背
The background is the area "behind" the earth. The default color of the background is background 0x000000. Background color can be set through configure() as follow: controller.configure({ col