Taylor Abernethy Newman
Taylor Abernethy Newman

Reputation: 1162

navgiator.notification.alert() on Android not working.. Phonegap 3.0

I have a phonegap app that is working perfectly on iOS.. it has now come time to port it to android... I am using phonegap 3.0 so the CLI installs the plugin however it still does not work.

Here is my code for the page requiring the alert or in this case the confirm.

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
   {
   }                                       
}  

Could someone please help me with what I should be checking in my files? I am very new an Android dev so it might be the .java file or the config.xml?

EDIT: I should add that there are no errors being thrown in the log etc... and there is an alert() on either side of the confirm that gets called... its just as if it passes over the code..

Upvotes: 3

Views: 6548

Answers (2)

Taylor Abernethy Newman
Taylor Abernethy Newman

Reputation: 1162

I found the solution was infact with my config.xml...

I was using :

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

Which is what phone gap have on their install page.. but infact I needed to change the feature to:

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

Upvotes: 4

Vicky Gonsalves
Vicky Gonsalves

Reputation: 11717

Your code has errors try below code:

 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');
    }

Upvotes: 0

Related Questions