简体   繁体   English

Cordova中没有插件可用

[英]No plugins are working in Cordova

I can successfully install all plugins but none of them seems to work. 我可以成功安装所有插件,但它们似乎都不起作用。

I have also the cordova.js included: 我还包括了cordova.js:

<script type="text/javascript" src="cordova.js"></script>
<script src="js/jquery.js"></script>
<script src="js/tocca.js"></script>
<script type="text/javascript" src="js/index.js"></script>

Then when I use simple $('.curpos').html(device.cordova); 然后当我使用简单的$('.curpos').html(device.cordova); in index.js, it does not work. 在index.js中,它不起作用。

This is output from cordova plugin command: 这是从cordova plugin命令输出的:

com.admob.pro 2.6.2 "AdMob Plugin Pro"
com.google.playservices 19.0.0 "Google Play Services for Android"
com.rjfun.cordova.extension 1.1.4 "Cordova Plugin Extension"
org.apache.cordova.device 0.3.0 "Device"

Can anybody point to solution? 有人可以指出解决方案吗?

Edit: 编辑:

This is my index.js 这是我的index.js

document.addEventListener("deviceready", onDeviceReady(), false);
function onDeviceReady() {
    console.log(window.cordova);
    viewport = {
        width: $(window).width(),
        height: $(window).height()
    };
    // reklamy

    var ad_units = {
        android: {
            banner: ''
        }
    };

    var admobid = ad_units.android;
//      if (AdMob) {
//          AdMob.createBanner({
//              adId: admobid.banner,
//              position: AdMob.AD_POSITION.TOP_CENTER,
//              autoShow: true
//          });
//      }
    console.log(window.cordova);
    $('.curpos').html(device.cordova);

    $('.hello').html("<span style='color:green;'>Loaded!</span>");
    var doc = document.createElement("div");
    $(doc).html("Šířka: " + viewport.width + "<br>Výška: " + viewport.height);
    $('body').append("<div class='curpos'></div>");
    $('body').append(doc);
    $('body').append("<div style='position: absolute; z-index:-1; left: 0; top: 0; width: " + viewport.width + "px; height: " + viewport.height + "px; background: red;'></div>");
    $('body').on("tap", function (e, data) {
        var x = data.x;
        var y = data.y;
        $('.curpos').html("X: " + x + "<br>Y: " + y);
    });
}

Stringified version of window.cordova: window.cordova的字符串化版本:

{"version":"3.7.1","platformVersion":"3.7.1","platformId":"android","callbackId":879098886,"callbacks":{},"callbackStatus":{"NO_RESULT":0,"OK":1,"CLASS_NOT_FOUND_EXCEPTION":2,"ILLEGAL_ACCESS_EXCEPTION":3,"INSTANTIATION_EXCEPTION":4,"MALFORMED_URL_EXCEPTION":5,"IO_EXCEPTION":6,"INVALID_ACTION":7,"JSON_EXCEPTION":8,"ERROR":9}}

I made a sample app with your configuration and had the same issue, but I found out that you were missing something (comparing to a cordova app of mine). 我用您的配置制作了一个示例应用程序,并且遇到了同样的问题,但是我发现您缺少了一些东西(与我的cordova应用程序相比)。

HTML - add onload attribute on body tag: onload在body标签上添加onload属性:

<body onload="onLoad()">

..and in your index.js file - wrap deviceready listener inside onLoad fn: ..和在index.js文件中-将deviceready侦听器包装在onLoad fn中:

function onLoad(){
   document.addEventListener("deviceready", onDeviceReady(), false);
}

That should work! 那应该工作! :) :)

Normally, it should work without this, but for some reason it doesn't. 通常,没有此功能它应该可以工作,但是由于某种原因却没有。 I guess it has something to do with cordova/android/plugin version. 我想这与cordova / android / plugin版本有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM