deviceready won't fire in Phonegap 1.0.0 on Android

前端 未结 2 1107
我在风中等你
我在风中等你 2020-12-29 14:52

I\'ve tried to setup Phonegap on Android and deviceready won\'t fire. The reason is that DeviceInfo.uuid is always null/undefined.

It seems

相关标签:
2条回答
  • 2020-12-29 15:23

    In case someone else stumble on this problem.

    I hadn't realized that phonegap-1.0.0.js is different for the iPhone and Android version. It has the same name, but the content is different. Thus, one must load the correct file. I solved it like this:

    <script type="text/javascript">
        // Atrocious way of loading two diffent phonegap scripts, but other loading methods won't work.
        // also there shouldn't be two scripts to begin with -- so much for cross-platform.
        var userAgent = navigator.userAgent.toLowerCase();
        if (userAgent.match(/android/)) {
        document.write("<script type='text/javascript' src='javascripts\/phonegap-android-1.0.0.js'><\/script>");
      } else {
        document.write("<script type='text/javascript' src='javascripts\/phonegap-iphone-1.0.0.js'><\/script>");
      }
    </script>
    
    0 讨论(0)
  • 2020-12-29 15:31

    If you want some function to execute when the device is ready do something like this

    document.addEventListener("deviceready", onDeviceReady, true);
    // PhoneGap is now ready
    
    function onDeviceReady() {
    // Write your code here
    }
    

    I am not sure why your code is not working.Try placing the document.addEventListener outside the scope of the function.

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