Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Detect the device level Notification ON or OFF using javascript for PWA Application?

My requirement is how to detect the device level notification on/off in android device using javascript (don't use any kind of plug-in only you can use plug-in if this plugin support to PWA application).

As per if notification off I need to show the pop up to user please enable the notification feature you'll get notifications.

Below answer is only for detective browser level notification. If anybody know Please give me exact answer how to do it. Because,I stopped there.

Please check the image here user enable once if user disable then I'm unable to send notification.

enter image description here

like image 968
Prabhat Avatar asked Nov 09 '19 05:11

Prabhat


People also ask

Can PWA have notifications?

The possibilities of PWA's are huge, and using DEITY Falcon Platform, you can easily integrate Web Push Notifications directly into your PWA front-end.


1 Answers

The feature seems to be well documented, have you tried:

function notifyMe() {
  // Let's check if the browser supports notifications
  if (!("Notification" in window)) {
    console.log("This browser does not support desktop notification");
  }

  // Let's check whether notification permissions have alredy been granted
  else if (Notification.permission === "granted") {
    // If it's okay let's create a notification
    var notification = new Notification("Hi there!");
  }

  // Otherwise, we need to ask the user for permission
  else if (Notification.permission !== 'denied' || Notification.permission === "default") {
    Notification.requestPermission(function (permission) {
      // If the user accepts, let's create a notification
      if (permission === "granted") {
        var notification = new Notification("Hi there!");
      }
    });
  }

  // At last, if the user has denied notifications, and you 
  // want to be respectful there is no need to bother them any more.
}
like image 105
Mosè Raguzzini Avatar answered Oct 04 '22 14:10

Mosè Raguzzini