Android Local Notification with Angular Service Worker

Viewed 1774

I'm building a PWA using the latest version of Angular.

I'm making use of the Angular Mobile Toolkit and I want to send Local Notifications using angular/service-worker. But I can't make it work.

I'm able to subscribe and send notification from a server, but I would like to send a notification from my app itself. I tried using angular2-notifications, it works well on a desktop, but the constructor

new Notification(title, options) 

from the Notification API doesn't work anymore on Android, so it doesn't suit me.

Is there any way to use angular/service-worker to send local notifications on Android (Chrome)? Or maybe another alternative.

EDIT

Maciej answer pointed me to the right direction, I was able to make it work using the following piece of code

navigator.serviceWorker.getRegistration() 
         .then((reg) => { 
                reg.showNotification(title, noti); 
           });

P.S.: Be aware that I used this together with angular/service-worker. I used angular/service-worker to register the service-worker and the code above uses the registered service-worker. Also, be aware that for the service-worker to work you need a secure connection.

1 Answers
Related