Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

javascript - 如何使用PWA应用程序的javascript检测设备级别通知的开启或关闭?(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).(我的要求是如何使用javascript检测android设备中的设备级别通知开/关(不要使用任何类型的插件,除非此插件支持PWA应用程序,否则您可以使用该插件)。)

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.(如果用户禁用,请检查此处用户启用的图像,如果用户禁用,则无法发送通知。) 在此处输入图片说明   ask by Prabhat translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...