【问题标题】:PhoneGap error on deviceready event with HTML 5使用 HTML 5 的 deviceready 事件上的 PhoneGap 错误
【发布时间】:2012-06-23 04:20:56
【问题描述】:

我有一个可以想象的最简单的 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 版的安卓模拟器中运行它。

控制台错误:

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)

如果有人能指出需要做什么来纠正错误,我将不胜感激。

谢谢,

【问题讨论】:

    标签: android html cordova simulator


    【解决方案1】:

    我认为您遇到的问题是您的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;
    

    【讨论】:

    • devicereqady 不能在 window.onLoad 之前发生。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多