Calling Javascript Notification Api On Google Chrome For Android Not Working Directly From A Web Page
Solution 1:
On Chrome for Android you can only open a notification via a Service Worker. A service worker is a script that runs alongside the browser and can be loaded even when the page or browser are currently closed.
The main reasoning behind the service worker requirement is that a notification can outlive the length of the browser's lifetime (i.e, the user can close the browser) and the notification will still be active, therefore when a user clicks on the notification Android needs to wake "something" up, this "something" is the Service Worker.
This Notification Guide is a good introduction to the current state of Notifications on the Web and in Chrome - it focuses a little on Push messaging but also has all the details of how to trigger a notification from the Service Worker.
This might seem like an extra hoop to jump through but it actually is a net benefit: your notification will still work when clicked even when the browser is closed.
Solution 2:
Check this for compatibility: http://caniuse.com/#feat=notifications
"Partial Support" Although as Kinlan mentioned, it's possible with Web Service Workers.
navigator.serviceWorker.register('sw.js');
Notification.requestPermission(function(result) {
if (result === 'granted') {
navigator.serviceWorker.ready.then(function(registration) {
registration.showNotification('Notification with ServiceWorker');
});
}
});
The sw.js
file can just be a zero-byte file.
Credit Due: HTML5 Notification not working in Mobile Chrome
Post a Comment for "Calling Javascript Notification Api On Google Chrome For Android Not Working Directly From A Web Page"