javascript - How to dismiss a phonegap notification programmatically - Stack Overflow
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!
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!
Share Improve this question asked Aug 31, 2011 at 0:27 InatorInator 1,0242 gold badges16 silver badges34 bronze badges3 Answers
Reset to default 2Hey 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, pleteCallback, title, buttonLabel) {
var _title = (title || "Alert");//Doesnt Matter!
var _buttonLabel = (buttonLabel || "OK");//Doesnt Matter!
exec(pleteCallback, 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.
You can't programmatically dismiss an alert()
dialog, no.
What you could do, however, is instead of using alert()
implement your own custom overlay that looks/acts similarly to an alert, and then you can easily dismiss that whenever you want. Some additional discussion is here:
Javascript close alert box
Edit
I did a bit more investigation into this and I no longer believe that the Phonegap alert()
dialog is actually the same as the native JavaScript dialog. They are using some clever tricks to call back into native code (on both Android and iOS) to show the alert.
As such, it may be possible to dismiss the dialog programmatically, but almost certainly not from directly within your JavaScript code. You would need to use some similar trickery to call back from your JavaScript into native code, and then locate and dismiss the Phonegap alert view. The first part may be fairly difficult. The second part is trivial:
Hide UIAlertView programmatically?
Perhaps create a dialog out of a div or some other element and display that to the user so you can dismiss it easily.
JavaScript
function geo_error() {
//only append error message if none exists
if ($('#page_container').find('.geo_error').length == 0) {
$('#page_container').append('<div class="geo_error">A Geolocation Error Has Occured</div>');
}
}
function get_success(position) {
//hide the error message on success
$('#page_container').find('.geo_error').hide();
}
CSS
.geo_error {
position: absolute;
top: 10px;
bottom: 10px;
left: 20px;
right: 20px;
z-index: 1000;
}
- 都想取代PC 这些产品究竟还欠缺什么?
- 移动互联网迅猛发展连接人与服务成为重要趋势
- 谷歌收购摩托实现软硬件并举:将开启全新时代
- electron - Windows task scheduler triggers the task but it is not invoking the app which I want to open on system login - Stack
- mip sdk - Can you use the mip sdk to apply a mpip sensitivity label to a .json? - Stack Overflow
- Udev rule for syfs classdevice attributes - Stack Overflow
- python - How to sub-class LangGraph's MessageState or use Pydantic for channel separation - Stack Overflow
- google colaboratory - Load a Kaggle dataset into Colab notebook without extracting it - Stack Overflow
- Parsing Swift Predicates into Database Statements with PredicateExpressions - Stack Overflow
- python - Can't run pytest with a `FileNotFoundError: [Errno 2] No such file or directory: 'tmppip-build-env-3fag
- differential equations - Calculating a rocket trajectory in Matlab - Stack Overflow
- docker - Python Telegram bot freezes when run by Airflow - Stack Overflow
- Angular lib with route - Stack Overflow
- docker - Pulling AWS Parameter Store secrets into a deployed Dockerized app on EC2 - Stack Overflow
- javascript - useState rerenders bindings increment when key added to object but not removed - Stack Overflow
- node.js - Nestjs can't find build source after creating workspace - Stack Overflow
- Is there showhide functionality for boiler plate content in google docs? - Stack Overflow