deviceready不会在PhoneGap的1.0.0火灾在Android [英] deviceready won't fire in Phonegap 1.0.0 on Android

查看:106
本文介绍了deviceready不会在PhoneGap的1.0.0火灾在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图安装的PhoneGap在Android和 deviceready 将不会触发。其原因是, DeviceInfo.uuid 总是空/未定义。

这似乎是PhoneGap的是不正确装入非JavaScript部分,但我看不出到底是什么。对于www目录之外的一切我使用了PhoneGap的下载的样本目录中提供的code。

任何人都知道可能会导致此?

 <!DOCTYPE HTML>
< HTML>
  < HEAD>
    < META NAME =视口内容=WIDTH =装置宽度,初始规模= 1.0,最大规模= 1.0,用户可扩展性=无; />
    < META HTTP-当量=内容类型内容=text / html的;字符集= UTF-8>

      <脚本类型=文/ JavaScript的字符集=utf-8SRC =JavaScript的/ PhoneGap的-1.0.0.js>< / SCRIPT>
    &所述;脚本的src =htt​​p://debug.phonegap.com/target/target-script-min.js#something>&所述; /脚本>

    <脚本类型=文/ JavaScript的字符集=utf-8>

    功能onBodyLoad(){
      VAR初始化=功能(){
        window.console.log(deviceready ||简历);
      };
      document.addEventListener(deviceready,初始化);
      document.addEventListener(恢复,初始化);
      window.console.log(onBodyLoad!);
    }

    < / SCRIPT>
  < /头>
  <身体的onload =onBodyLoad()>
  < H1>赫罗世界< / H1>
  < /身体GT;
< / HTML>
 

解决方案

在对这个问题的情况下别人摔跟头。

我还没有意识到,PhoneGap的,1.0.0.js是为iPhone和Android版本不同。它具有相同的名称,但内容是不同的。因此,人们必须加载正确的文件。我解决了它是这样的:

 <脚本类型=文/ JavaScript的>
    //中装入两张diffent PhoneGap的脚本残暴的方式,但其他的加载方法将无法正常工作。
    //也不应有两个脚本开始说起 - 这么多的跨平台。
    变种的userAgent = navigator.userAgent.toLowerCase();
    如果(userAgent.match(/安卓/)){
    的document.write(<脚本类型=文/ JavaScript的SRC =JavaScript的\ /phonegap-android-1.0.0.js'>< \ / SCRIPT>中);
  } 其他 {
    的document.write(<脚本类型=文/ JavaScript的SRC =JavaScript的\ /phonegap-iphone-1.0.0.js'>< \ / SCRIPT>中);
  }
< / SCRIPT>
 

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 like the non-javascript parts of phonegap isn't loaded correctly, but I can't see exactly what. For everything outside the www directory I'm using the code provided in the sample directory of the phonegap download.

Anyone know what may be causing this?

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">

      <script type="text/javascript" charset="utf-8" src="javascripts/phonegap-1.0.0.js"></script>
    <script src="http://debug.phonegap.com/target/target-script-min.js#something"></script>

    <script type="text/javascript" charset="utf-8">

    function onBodyLoad() {
      var initialize = function() {
        window.console.log("deviceready||resume");
      };
      document.addEventListener("deviceready", initialize);
      document.addEventListener("resume", initialize);
      window.console.log("onBodyLoad!");
    }

    </script>
  </head>
  <body onload="onBodyLoad()">
  <h1>Herro World</h1>
  </body>
</html>

解决方案

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>

这篇关于deviceready不会在PhoneGap的1.0.0火灾在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆