我在我的应用程序中安装了这个很棒的Cordova插件,以使其在后台运行。
$ cordova plugin add https://github.com/katzer/cordova-plugin-background-mode.git
该插件使用以下方法创建对象cordova.plugins.backgroundMode:
backgroundMode.enable
backgroundMode.disable
backgroundMode.isEnabled
backgroundMode.isActive
backgroundMode.getDefaults
backgroundMode.setDefaults
backgroundMode.configure
backgroundMode.onactivate
backgroundMode.ondeactivate
backgroundMode.onfailure
现在我正在使用我想在backbutton上发送的cordova backbutton事件,将应用程序发送到这样的backgroundMode,但它不起作用。
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown() {
// Handle the back button
backgroundMode.enable();
}
非常感谢任何帮助。
答案 0 :(得分:-1)
尝试,
document.addEventListener('deviceready', function () {
// Android customization
cordova.plugins.backgroundMode.setDefaults({ text:'Doing heavy tasks.'});
// Enable background mode
cordova.plugins.backgroundMode.enable();
// Called when background mode has been activated
cordova.plugins.backgroundMode.onactivate = function () {
setTimeout(function () {
// Modify the currently displayed notification
cordova.plugins.backgroundMode.configure({
text:'Running in background for more than 5s now.'
});
}, 5000);
}
}, false);