简体   繁体   English

phonegap / cordova onDeviceReady()无法触发android 4.1.2

[英]phonegap/cordova onDeviceReady() not firing android 4.1.2

I am at my wits end here. 我的智慧到此为止。 I am using Adobe Build and PhoneGap Version 3.5.0 and Cordova 3.4.0. 我正在使用Adobe Build和PhoneGap版本3.5.0和Cordova 3.4.0。

No matter what I do, my onDeviceReady() event does not fire on my android device, either as an APK or in the PhoneGap developer app. 无论我做什么,我的onDeviceReady()事件都不会以APK或PhoneGap开发人员应用程序的形式在Android设备上触发。

Here is my config.xml: 这是我的config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.ourwalmart" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
  <name>xxxx</name>
  <description>
xxxx  </description>
  <author email="xx@xxx.org" href="http://xxxxxxx.org">
    OUR Walmart
  </author>
  <preference name="permissions" value="none" />
  <preference name="phonegap-version" value="3.5.0" />
  <preference name="orientation" value="default" />
  <preference name="target-device" value="universal" />
  <preference name="fullscreen" value="true" />
  <preference name="webviewbounce" value="false" />
  <preference name="prerendered-icon" value="true" />
  <preference name="stay-in-webview" value="false" />
  <!--<preference name="ios-statusbarstyle" value="black-translucent" />-->
  <preference name="detect-data-types" value="true" />
  <preference name="exit-on-suspend" value="false" />
  <!--<preference name="show-splash-screen-spinner" value="true" />
  <preference name="auto-hide-splash-screen" value="true" />-->
  <preference name="disable-cursor" value="false" />
  <preference name="android-minSdkVersion" value="7" />
  <preference name="android-installLocation" value="auto" />
  <gap:plugin name="com.phonegap.plugin.statusbar" />
  <gap:plugin name="org.apache.cordova.battery-status" />
  <gap:plugin name="org.apache.cordova.camera" />
  <gap:plugin name="org.apache.cordova.media-capture" />
  <gap:plugin name="org.apache.cordova.console" />
  <gap:plugin name="org.apache.cordova.contacts" />
  <gap:plugin name="org.apache.cordova.device" />
  <gap:plugin name="org.apache.cordova.device-motion" />
  <gap:plugin name="org.apache.cordova.device-orientation" />
  <gap:plugin name="org.apache.cordova.dialogs" />
  <gap:plugin name="org.apache.cordova.file" />
  <gap:plugin name="org.apache.cordova.file-transfer" />
  <gap:plugin name="org.apache.cordova.geolocation" />
  <gap:plugin name="org.apache.cordova.globalization" />
  <gap:plugin name="org.apache.cordova.inappbrowser" />
  <gap:plugin name="org.apache.cordova.media" />
  <gap:plugin name="org.apache.cordova.network-information" />
  <gap:plugin name="org.apache.cordova.splashscreen" />
  <gap:plugin name="org.apache.cordova.vibration" />
  <icon src="icon.png" />
   <icon gap:platform="android" gap:qualifier="ldpi" src="res/icon/android/icon-36-ldpi.png" />
    <icon gap:platform="android" gap:qualifier="mdpi" src="res/icon/android/icon-48-mdpi.png" />
    <icon gap:platform="android" gap:qualifier="hdpi" src="res/icon/android/icon-72-hdpi.png" />
    <icon gap:platform="android" gap:qualifier="xhdpi" src="res/icon/android/icon-96-xhdpi.png" />
    <icon gap:platform="blackberry" src="res/icon/blackberry/icon-80.png" />
    <icon gap:platform="blackberry" gap:state="hover" src="res/icon/blackberry/icon-80.png" />
    <icon gap:platform="ios" height="57" src="res/icon/ios/icon-57.png" width="57" />
    <icon gap:platform="ios" height="72" src="res/icon/ios/icon-72.png" width="72" />
    <icon gap:platform="ios" height="114" src="res/icon/ios/icon-57-2x.png" width="114" />
    <icon gap:platform="ios" height="144" src="res/icon/ios/icon-72-2x.png" width="144" />
    <icon gap:platform="webos" src="res/icon/webos/icon-64.png" />
    <icon gap:platform="winphone" src="res/icon/windows-phone/icon-48.png" />
    <icon gap:platform="winphone" gap:role="background" src="res/icon/windows-phone/icon-173.png" /> 
  <gap:splash gap:platform="android" gap:qualifier="port-ldpi" src="res/screen/android/screen-ldpi-portrait.png" />
  <gap:splash gap:platform="android" gap:qualifier="port-mdpi" src="res/screen/android/screen-mdpi-portrait.png" />
  <gap:splash gap:platform="android" gap:qualifier="port-hdpi" src="res/screen/android/screen-hdpi-portrait.png" />
  <gap:splash gap:platform="android" gap:qualifier="port-xhdpi" src="res/screen/android/screen-xhdpi-portrait.png" />
  <gap:splash gap:platform="blackberry" src="res/screen/blackberry/screen-225.png" />
  <gap:splash gap:platform="ios" height="480" src="res/screen/ios/screen-iphone-portrait.png" width="320" />
  <gap:splash gap:platform="ios" height="960" src="res/screen/ios/screen-iphone-portrait-2x.png" width="640" />
  <gap:splash gap:platform="ios" height="1136" src="res/screen/ios/screen-iphone-portrait-568h-2x.png" width="640" />
  <gap:splash gap:platform="ios" height="1024" src="res/screen/ios/screen-ipad-portrait.png" width="768" />
  <gap:splash gap:platform="ios" height="768" src="res/screen/ios/screen-ipad-landscape.png" width="1024" />
  <gap:splash gap:platform="winphone" src="res/screen/windows-phone/screen-portrait.jpg" />
  <access origin="*" />

</widget>

Here is my index.html file: 这是我的index.html文件:

<head>
    <title></title>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />        
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1" />

    <!--Styles-->

    <!--Javascript-->
    <script src="js/libs/jquery/jquery-1.9.1min.js" type="text/javascript" charset="utf-8"></script>
    <!--Phone Gap-->
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="phonegap.js"></script>

    <script>
        /* Set jQueryMobile default behavior */
        $(document).bind("mobileinit", function () {
            $.mobile.defaultPageTransition = "slide";
        });

        function onError(errorText) {  //default error behavior
            globalVarStore.error.message = errorText;
            $.mobile.loading('hide');
            $.mobile.changePage("error.html", { role: "dialog" });
        }
    </script>

    <!--Jquery Mobile / Libs-->
    <script src="js/libs/jqmobile/jqmobile.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/libs/jquery.validate.js" type="text/javascript" charset="utf-8"></script>

    <!---Page Controllers-->


    <script>
            app.initialize();

        $(function () {
            //some jquery stuff here.                              
        });

    </script>        
</head>

And here is my index.js file that contains the deviceReady handler. 这是我的index.js文件,其中包含deviceReady处理程序。 This works fine for iPhone. 这对于iPhone来说效果很好。

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:

    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler           
    onDeviceReady: function () {
    itDoesntMatterWhatIsHereItDoesntFire();
    },

Calling app.initialize() in the header will not guarantee that the page is ready. 在标题中调用app.initialize()不能保证页面已准备就绪。 Try adding this to the onload property of the body: 尝试将其添加到主体的onload属性中:

<body onload="app.initialize()">

Sorry for even posting this. 抱歉甚至发布了此信息。 It turns out that in one of my JS files I had included the line. 事实证明,在我的一个JS文件中,我包括了这一行。

window._cordovaNative = true;

This mean that it was not going into prompt mode for my older Samsung Galaxy II I was testing on. 这意味着对于我正在测试的较旧的三星Galaxy II,它没有进入提示模式。 If anyone else runs into this problem, check to make sure that you don't have this line anywhere in your code! 如果还有其他人遇到此问题,请检查以确保您的代码中没有此行!

It's useful for debugging on the browser, but kills the app for older phones. 这对于在浏览器上进行调试很有用,但会终止旧手机的应用程序。

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

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