Android上的navigator.notification.alert()无法正常工作.. Phonegap 3.0

时间:2013-10-22 00:54:42

标签: android cordova phonegap-plugins

我有一个在iOS上完美运行的phonegap应用程序..它现在有时间将它移植到android ...我正在使用phonegap 3.0所以CLI安装插件但它仍然无法正常工作。

以下是我需要提醒的页面的代码,或者在这种情况下是确认。

function onDeviceReady() {
            //setup page
alert('deviceRead');
}

 navigator.notification.confirm(
 'blah blah',  // message
  onConfirm,  // callback to invoke with index of button pressed
  'title',    // title
  'cancel','ok'    // buttonLabels
  );


  function onConfirm(button) {

  if(button == 2)
  {
    alert('button 2 pressed');
  }
   else
   {
   }                                       
}  

有人可以帮助我查看我应该检查的文件吗?我是一个非常新的Android开发人员,所以它可能是.java文件或config.xml?

编辑:我应该补充一点,在日志等中没有抛出错误...并且在确认的任何一侧都有一个alert()被调用...就像它传递代码一样..

2 个答案:

答案 0 :(得分:4)

我发现解决方案实际上是我的config.xml ...

我正在使用:

<feature name="Notification">
<param name="android-package" value="org.apache.cordova.Notification" />
</feature>

这是他们的安装页面上的电话差距..但实际上我需要将功能更改为:

<feature name="Notification">
<param name="android-package" value="org.apache.cordova.dialogs.Notification" />
</feature>

答案 1 :(得分:0)

您的代码有错误,请尝试以下代码:

 function onDeviceReady() {

        navigator.notification.alert(
                'This is Alert',  
                onOK,  
                'Alert', 
                'ok'   
        );

        navigator.notification.confirm(
                'This is confirm',  // message
                onConfirm,  // callback to invoke with index of button pressed
                'button 2',    // title
                'cancel', 'ok'    // buttonLabels
        );


    }


    function onConfirm(button) {
        if (button == 2) {
            alert('button 2 pressed');
        } else {

        }
    }


    function onOK() {
        alert('OK pressed');
    }