我已经创建了一个简单的Web应用程序通知(使用教程),以使用Notification API测试推送通知,但是它不适用于我的Android手机(通知权限已在手机上授予),我正在使用Android 8.0和Chrome 77。 这是链接:https://www.niclamarino.com/prove.php 我不是Android开发人员,所以我很困惑,有什么我错过的地方吗?谢谢!
我的代码
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Notification API</title>
<meta name="viewport" content="width=device-width">
</head>
<body>
<h1>Notification API</h1>
<p id="output"></p>
<script>
if( 'Notification' in window){
if (Notification.permission === 'granted') {
doNotify();
}else{
Notification.requestPermission()
.then(function(result) {
if( Notification.permission == 'granted'){
doNotify();
}
})
.catch( (err) => {
console.log(err);
});
}
}
function doNotify(){
let title = "The Title";
let t = Date.now() + 120000; // 2 mins in future
let options = {
body: 'Hello from JavaScript!',
data: {prop1:123, prop2:"Nicla"},
lang: 'en-NY',
icon: 'http://educazionetecnica.dantect.it/wp-content/uploads/2012/09/STAR-icon.png',
timestamp: t,
vibrate: [100, 200, 100]
}
let n = new Notification(title, options);
setTimeout( n.close.bind(n), 3000); //close notification after 3 seconds
}
</script>
</body>
</html>