PhoneGap - OnDeviceReady method not getting called

前端 未结 3 1403
北荒
北荒 2020-12-20 01:52

I am developing my first application in phonegap (android).

index.html

 
    
      
        

        
相关标签:
3条回答
  • 2020-12-20 02:27

    Follow it this way and it should be working.

    <!DOCTYPE html>
    <html>
      <head>
        <title>Cordova Device Ready Example</title>
    
        <script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
        <script type="text/javascript" charset="utf-8">
    
        // Call onDeviceReady when Cordova is loaded.
        //
        // At this point, the document has loaded but cordova-1.7.0.js has not.
        // When Cordova is loaded and talking with the native device,
        // it will call the event `deviceready`.
        //
        function onLoad() {
            document.addEventListener("deviceready", onDeviceReady, false);
        }
    
        // Cordova is loaded and it is now safe to make calls Cordova methods
        //
        function onDeviceReady() {
            // Now safe to use the Cordova API
        }
    
        </script>
      </head>
      <body onload="onLoad()">
      </body>
    </html>
    

    Also check the Android example folder in the Cordova 1.7 download.

    0 讨论(0)
  • 2020-12-20 02:37

    I got a solution for my one!! It's really simple problem on acquaintance.

    We usually develop one cordova(phonegap) project, and then copy all related files (/www) to another one. but I realized Cordova file (cordova-2.2.0 now) is different between platforms.

    Do not copy even cordova file. Use original example one on the platform.

    not sure for every case. is this helpful? :)

    0 讨论(0)
  • 2020-12-20 02:48

    For everyone who is still in trouble looking for solution - check the alternative .js files imported into your index.html, for example the index.js might have its own device ready call and function, therefore blocking your custom one.

    0 讨论(0)
提交回复
热议问题