Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dismiss a phonegap notification programmatically

Is there any way to programmatically dismiss navigator.notification.alert()? I alert when there's a location services error, but if it clears, I'd prefer to dismiss it rather than require the user to do it manually.

Any ideas or solutions?

Thanks!

like image 448
Inator Avatar asked Aug 31 '11 00:08

Inator


1 Answers

Hey i have got a change in java file for this. src/android/Notification.java

Added a reference to dlg.create()

First Declare this..

private AlertDialog alertbox;

Then add a case where you send "dismiss" from javascript

else if (action.equals("dismiss")) {
     this.dismissAll();
}

Method to be added :

public void dismissAll(){
    alertbox.dismiss();
}

Do remember to add the same in notification.js in www folder of notification plugin

dismiss: function(message, completeCallback, title, buttonLabel) {
    var _title = (title || "Alert");//Doesnt Matter!
    var _buttonLabel = (buttonLabel || "OK");//Doesnt Matter!
    exec(completeCallback, null, "Notification", "dismiss", [message, _title, _buttonLabel]);
},

Now add

alertbox = dlg.create();
alertbox.show();

instead of

dlg.create();
dlg.show();

at all the places.

And you are good to go by calling

navigator.notification.dismiss("",null,"");

This will dismiss all the alerts / confirm / prompt opened.

like image 114
Dhruv Parikh Avatar answered Oct 15 '22 13:10

Dhruv Parikh