onDeviceReady()不会在Crosswalk Cordova项目中解雇

时间:2015-04-10 06:45:06

标签: android cordova crosswalk-runtime

当我在Crosswalk-Cordova项目中运行它时,onDeviceRead()方法不会触发。

我测试了以下版本的Crosswalk Cordova Android(ARM):

-11.40.277.7
-12.41.296.4
-13.41.313.0

我正在使用cordova 3.6.3

这是HTML-File中的代码:

<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />                         
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Test</title>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>
    <script type="text/javascript" charset="utf-8">

    function onLoad() {

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

        // device APIs are available
        //
        function onDeviceReady() {
            alert("123");
        }            

    </script>

</head>
<body onload="onLoad()">
    <div class="app">
        <h1>Apache Cordova</h1>
        <div id="deviceready" class="blink">
            <p class="event listening">Connecting to Device</p>
            <p class="event received">Device is Ready</p>
        </div>
    </div>

</body>

以下是cordova的文档:http://docs.phonegap.com/en/edge/cordova_events_events.md.html#deviceready

提前致谢!

1 个答案:

答案 0 :(得分:0)

如果你能看到Apache cordova. Device is Ready这意味着已经初始化了cordova api。 Apache cordova. Device is Ready由位于app.initialize()文件中的index.js调用设置。

使其更简单。只需评论app.initialize()电话。删除body标记中的onload属性,并替换 脚本标记中的以下代码。

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

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

  // device APIs are available
  //
  function onDeviceReady() {
        alert("123");
  }            

</script>

您应该会在屏幕上看到提醒。