【发布时间】:2018-02-08 13:51:25
【问题描述】:
我对 Cordova 有另一个问题。我想在 Cordova 7.1.0 中使用插件“cordova.custom.plugins.exitapp”和“cordova-plugins-printer”。
在服务器端,我将 document.AddEventListener 构建到 $(document).ready(function() {});
.js:
$(document).ready(function(){
...
document.addEventListener("deviceready", exitFromApp, false);
...
}),
function exitFromApp() {
console.log("NAVIGATOR: " + navigator);
console.log("NAVIGATOR.APP: " + navigator.app);
console.log("NAVIGATOR.APP.EXITAPP: " + navigator.app.exitApp());
navigator.app.exitApp();
}
无论我是否使用 addEventListener,Android Studio 总是说:
- deviceready 在 5 秒后未触发。
- 频道未触发:onPluginsReady
- 频道未触发:onCordovaReady
但不同的是addEventListener不调用exitFromApp()函数。
当我直接调用exitFromApp() 时,它可以工作,但 navigator.app 未定义(或 cordova.plugins / window.plugins 未定义)。
cordova.js 在 header.php 中调用,因此始终可用。
如果我通过平板电脑上的 index.html 使用插件,它可以工作。
我已经在config.xml中设置了权限:
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="*" />
安装:
科尔多瓦 7.1.0
cordova-plugin-inappbrowser 2.0.1
cordova-plugin-network-信息 2.0.1
cordova-plugin-whitelist 1.3.3
cordova.custom.plugin.exitapp 1.0.0
phonegap.plugin-barcodescanner 7.0.1
cordova-plugin-printer 0.7.3
【问题讨论】:
标签: javascript android cordova cordova-plugins