繁体   English   中英

使用HTML 5在deviceready事件上发生PhoneGap错误

[英]PhoneGap error on deviceready event with HTML 5

我有一个可以想象的最简单的PhoneGap应用!

我要做的就是在deviceready事件中显示警报消息。

HTML代码

<!DOCTYPE HTML>
<html>
<head>
    <title>PhoneGap</title>
    <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
    <script type="text/javascript" charset="utf-8" src="common.js"></script>
</head>
<body>
    <div data-role="page" id="index-page">
        <h1>Hello World!</h1>
</body>
</html> 

common.js代码

var isPhoneGapReady = false;
function init() {

        document.addEventListener("deviceready", 
            onDeviceReady, false);

        // Older versions of Blackberry < 5.0 don't support 
        // PhoneGap's custom events, so instead we need to 
        // perform an interval check every 500 milliseconds 
        // to see if PhoneGap is ready.  Once done, the 
        // interval will be cleared and normal processing
        // can begin
        var intervalID = window.setInterval(function() {
              if (PhoneGap.available) {
                  onDeviceReady();
              }
          }, 500);
  }

function onDeviceReady() {
    window.clearInterval(intervalID);

    // set to true
    isPhoneGapReady = true;
alert("The device is now ready");
}

// Set an onload handler to call the init function
window.onload = init;

我正在使用云服务来获取APK文件,并且正在4.0.3版本的ANdroid模拟器中运行它。

控制台错误:

init
Ignote this event
W/webcore(6387): java.lang.Throwable: EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up.
at android.webkit.WebViewCore$EventHub.removeMessages(WebViewCore.java:1683)

如果有人可以指出要更正错误的位置,我将不胜感激。

谢谢,

我认为您遇到的问题是intervalID的范围未达到onDeviceReady()函数。 您需要在init()函数中创建该函数,如下所示:

var isPhoneGapReady = false;

function init() {

    document.addEventListener("deviceready", onDeviceReady, false);

    // Older versions of Blackberry < 5.0 don't support 
    // PhoneGap's custom events, so instead we need to 
    // perform an interval check every 500 milliseconds 
    // to see if PhoneGap is ready.  Once done, the 
    // interval will be cleared and normal processing
    // can begin

    var intervalID = window.setInterval(function() {
          if (PhoneGap.available) {
              onDeviceReady();
          }
      }, 500);

        // REMOVE THIS
        // }

    function onDeviceReady() {
        window.clearInterval(intervalID);

        // set to true
        isPhoneGapReady = true;
    alert("The device is now ready");
    }

// PUT THIS HERE
}

// Set an onload handler to call the init function
window.onload = init;

暂无
暂无

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

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