Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用用于PWA应用程序的javascript检测设备级通知的打开或关闭?_Javascript_Jquery_Push Notification_Progressive Web Apps_Polymer 3.x - Fatal编程技术网

如何使用用于PWA应用程序的javascript检测设备级通知的打开或关闭?

如何使用用于PWA应用程序的javascript检测设备级通知的打开或关闭?,javascript,jquery,push-notification,progressive-web-apps,polymer-3.x,Javascript,Jquery,Push Notification,Progressive Web Apps,Polymer 3.x,我的要求是如何使用javascript在android设备中检测设备级别的开/关通知(不要使用任何类型的插件,只有在该插件支持PWA应用程序的情况下才能使用插件) 根据如果通知关闭,我需要向用户显示弹出窗口,请启用通知功能,您将收到通知 下面的答案仅适用于detective浏览器级别的通知。如果有人知道,请给我确切的答案怎么做。因为,我停在那里 请检查此处的图像“用户启用”一次,如果用户禁用,则我无法发送通知 该功能似乎很好,您是否尝试过: function notifyMe() { //

我的要求是如何使用javascript在android设备中检测设备级别的开/关通知(不要使用任何类型的插件,只有在该插件支持PWA应用程序的情况下才能使用插件)

根据如果通知关闭,我需要向用户显示弹出窗口,请启用通知功能,您将收到通知

下面的答案仅适用于detective浏览器级别的通知。如果有人知道,请给我确切的答案怎么做。因为,我停在那里

请检查此处的图像“用户启用”一次,如果用户禁用,则我无法发送通知


该功能似乎很好,您是否尝试过:

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.
}

Browser会返回那个,我不认为你们需要处理那个。浏览器只能在允许全部通知的情况下请求权限。如果需要,我们可以连接。@anshulix您的权利。我已经处理了浏览器级别。但是,如果用户离开设备级别,我就无法推送通知。所以,我不能在用户设备中直接启用,这就是为什么我至少要显示弹出窗口。浏览器只提供浏览器级别的通知状态。我猜你的意思是说喜欢(通知。权限)。有人能给出答案吗..请。。!!如果你已经在webapp中启用了android界面,那么你可以创建一个钩子来为你处理它。或者,您可以尝试
通知.requestPermission
。不确定它在定制移动网络应用程序上的效果如何。嘿..莫斯。。您的答案是针对浏览器级别的通知。。我在问关于设备级别的问题。如何检测?是的,我尝试并实现了浏览器级别。但我的库存超过了设备级别。。通知检测。@Prabhat根据MDN“通知API允许网页或应用程序发送在系统级别显示在页面外部的通知;这允许web应用程序向用户发送信息,即使应用程序处于空闲状态或在后台..”是,但如果用户在设备级别关闭通知,我将无法推送通知。。请检查我的屏幕截图。@这是浏览器安全性,要访问更高级别的信息,您应该将您的web应用包装在一个应用中,并直接请求操作系统,然后将信息传播到web视图。