0

我正在使用phonegap build来编译我的android apk,当我调用一个简单的

navigator.notification.alert(
      'This is my message',     // mensaje (message)
      alertDismissed,         // función 'callback' (alertCallback)
      'Game Over',            // titulo (title)
      'Close'                // nombre del botón (buttonName)
      );

它不起作用这是我的 index.html 代码

<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>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>PhoneGap</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
        </div>
        <script type="text/javascript" src="phonegap.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            app.initialize();
        </script>
    </body>
</html>

和我的 index.js

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicity call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');
    app.showAlert();
        console.log('Received Event: ' + id);
    },
    alertDismissed: function()
    {
      console.log('called function');
    },
    showAlert: function()
    {

     navigator.notification.alert(
      'Eres el ganador!',     // mensaje (message)
      alertDismissed,         // función 'callback' (alertCallback)
      'Game Over',            // titulo (title)
      'Cerrar'                // nombre del botón (buttonName)
      );
    },
};

应用程序启动并显示“设备已就绪”,但未出现警报

对不起我的英语,谢谢你的帮助

4

1 回答 1

0

尝试在<head>index.html 中包含所有脚本标签。我有一种感觉 deviceready 没有被调用,因为它在尝试加载 phonegap.js 时已经“准备好”了。

于 2013-09-10T11:10:07.167 回答