Node Programmer
Node Programmer

Reputation: 103

PhoneGap for Android deviceready not working

Problem is 'deviceready' event is not firing. Example app that comes with cordova works and I can copy it and create from there. But I need to know what is going wrong. I have tried everything (you can see the commented code). few important things.

  1. I created the project from here http://docs.phonegap.com/en/1.8.1/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android.
  2. I am using Jquery mobile and it is working fine.
  3. whole project is here http://www.filefactory.com/file/1pseohvngmuz/n/HelloCordova_zip

    /*************************************************************
    function init() {
        alert('init');
    }
    
    
    $(function() {
        alert('load');
    document.addEventListener("deviceready", function(){
          alert("123");
     },false);
    });
    
    $(document).ready(function(e) {
    });
    
     document.addEventListener("deviceready", onDeviceReady, true);
    function onDeviceReady()
    {
        alert('Phonegap ready');
    }
    ********************************************/
    function init() {
    
        document.addEventListener("deviceready", deviceInfo, false);
    }
    var deviceInfo = function() {
        alert('PhoneGap ready');
    };
    </script>
    

Thank you very much..

Upvotes: 0

Views: 7478

Answers (2)

Node Programmer
Node Programmer

Reputation: 103

found the bug myself. the cordova script file name was 'cordova-1.8.1.js'. while I was including 'cordova-1.8.0.js' and it took me two days to find it out.

Upvotes: 7

Simon MacDonald
Simon MacDonald

Reputation: 23273

Try this code to get deviceready with jQM

window.addEventListener('load', function () {
    document.addEventListener('deviceready', function () {
        alert("PhoneGap is now loaded!");
    }, false);
}, false);

Upvotes: 1

Related Questions