17

Consider the following.

if (this.Notification) {
  Notification.requestPermission(function(permission) {
    if (permission === 'granted') {
      return new Notification('hi this is a test');
    } else {
      return alert("Notifications not permitted");
    }
  });
} else {
  alert('Notifications not supported');
}

JSFiddle.

This seems to behave as expected in Chrome on desktop. In Firefox for Android, such notifications appear in the Android notification bar.

However on Android Chrome it seems to prompt the user to allow/disallow notifications, but if the user clicks 'allow' nothing seems to happen. Does Android Chrome support this sort of notification?

EDIT: This is different to this question from 18 months ago - then window.Notification wasn't defined at all. Now it is defined but doesn't seem to do anything.

Community
  • 1
  • 1
George Simms
  • 3,930
  • 4
  • 21
  • 35
  • 1
    possible duplicate of [Notification API in Android Chrome browser](http://stackoverflow.com/questions/21361968/notification-api-in-android-chrome-browser) – Pawel Uchida-Psztyc Aug 04 '15 at 21:51
  • 1
    @PawełPsztyć edited accordingly – George Simms Aug 05 '15 at 07:10
  • What version of Chrome do you have? – Josip Ivic Sep 23 '15 at 09:52
  • Mine is 45.0.2454.94 on Android 4.4.2, local notifications don't work, no errors either. – NOtherDev Sep 23 '15 at 18:42
  • Can you provide a jsfiddle for this? And did you check your settings in Chrome (Settings > Site Settings)? –  Sep 25 '15 at 20:22
  • 1
    @RalphWiggum jsfiddle included. – George Simms Sep 26 '15 at 08:47
  • @JosipIvic Funnily, my chrome is also 45.0.2454.94. – George Simms Sep 26 '15 at 08:49
  • 1
    @RalphWiggum Settings > Site Settings > Notification s is Ask First, with permission for JSFiddle after I first confirm it. Opening in incognito will prompt every time, of course. – George Simms Sep 26 '15 at 08:51
  • Could this be a Cross Origin Police as Fiddle uses iframe maybe child iframes are not allowed to call notifications. – Barkermn01 Sep 28 '15 at 10:07
  • @Martin Barker No, the same when loaded directly and on desktop works from iframe, too. – NOtherDev Sep 28 '15 at 14:36
  • 1
    I think this is a duplicate with the following question [HTML5 Notification not working in Mobile Chrome](http://stackoverflow.com/questions/31512504/html5-notification-not-working-in-mobile-chrome). When I debug it on my Android device, I get the following error: `Failed to construct 'Notification': Illegal constructor. Use ServiceWorkerRegistration.showNotification() instead.` – Swimburger Sep 28 '15 at 19:02
  • @sniels Ah... This is sad... https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/BygptYClroM Please post your comment as an answer. – NOtherDev Sep 28 '15 at 19:54

3 Answers3

2

I think this is a duplicate with the following question HTML5 Notification not working in Mobile Chrome. When I debug it on my Android device, I get the following error:

Failed to construct 'Notification': Illegal constructor. Use ServiceWorkerRegistration.showNotification()

turivishal
  • 34,368
  • 7
  • 36
  • 59
Swimburger
  • 6,681
  • 6
  • 36
  • 63
0

It should use servicework to show notification:

            navigator.serviceWorker.register("some-empty.js");
            Notification.requestPermission(function (result) {
                if (result === 'granted') {
                    navigator.serviceWorker.ready.then(function (registration) {
                        registration.showNotification('Notification with ServiceWorker');
                    });
                }
            });
Luar Faria
  • 31
  • 2
-2

Android does not receive chrome notifications, it is different from desktop chrome

Akshat Agarwal
  • 2,837
  • 5
  • 29
  • 49