How to reject a phone call notification programmatically

Is there a way to programmatically reject navigator.notification.alert ()? I warn of a location service error, but if it clears, I would rather reject it, rather than requiring the user to do this manually.

Any ideas or solutions?

Thanks!

+6
source share
3 answers

You cannot programmatically reject the alert() dialog, no.

However, you could use alert() implement your own custom overlay that looks / acts similar to a warning, and then you can easily drop it whenever you want. Some additional discussions here:

Block Javascript Warning

Edit

I did a bit more research on this and I no longer believe that the Phonegap alert() dialog actually matches the native JavaScript dialog. They use some smart tricks to call back to their own code (on Android and iOS) to show a warning.

Thus, it may be possible to cancel the dialog programmatically, but almost certainly not from your JavaScript code. You will need to use some of these tricks to call back from your JavaScript into your own code, and then find and reject the Phonegap warning view. The first part can be quite complicated. The second part is trivial:

Hide UIAlertView program code?

+1
source

Hi, I have a change in the java file for this. SRC / Android / Notification.java

Added link to dlg.create ()

Declare it first.

 private AlertDialog alertbox; 

Then add the case when you send the β€œfire” from javascript

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

Incremental method:

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

Remember to add the same to notification.js in the www folder of the 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

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

in all places.

And you can go by calling

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

This will reject all open alerts / confirmation / invitation.

+2
source

Perhaps create a dialog from a div or some other element and show it to the user so that you can easily drop it.

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; } 
0
source

Source: https://habr.com/ru/post/896268/


All Articles