'Push Notifications not working when Android inactive
I developed a PWA that subscribes to a push notification, and when a notification is received the Service Worker (SW) does a showNotification and a postMessage to each client, triggering them to update a display field in the browser. The client I'm testing on is Android 11 on a Pixel 5a, Chrome 99.0.4844.58, and the PSA is installed as an app.
Everything works fine while the phone screen is on (i.e. the notification pops up and the PWA display field is updated on the client), and it still works for several minutes after the screen times out and turns off/locks, but at some point (within about 5 minutes) the notifications no longer goes through. In the SW push event listener, I added a timestamp to the message that gets sent/displayed on the client browser, and is shows that the SW push event listener is not getting triggered until the phone is unlocked.
I've turned Settings>Battery>Adaptive Battery Off, and Battery Optimization to Not Optimized in the app settings for Chrome and the PSA app.
Is this the expected behavior? The intent of my PSA is for home monitoring, so it is essential that a notification occur even if the phone is "asleep".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|