Is there a way to add badge notifications using pr

2020-08-17 12:57发布

问题:

I'm developing a progressive web application (PWA) that will eventually send notifications to users.

I already know I'm able to send push notifications (like any regular app), as explained in the following blog post: https://developers.google.com/web/fundamentals/getting-started/codelabs/push-notifications/?hl=en-us.

I also know that I can add a PWA to the home screen, by creating a simple manifest file (https://developers.google.com/web/updates/2014/11/Support-for-installable-web-apps-with-webapp-manifest-in-chrome-38-for-Android).

However, after having the app in home screen, I would like to add a "hint" to users, letting they know that they have to access the application. A great way to do that is doing something like a "badge notification" (as showed in Facebook icon on the image below).

Is it possible to add this kind of behavior using progressive web applications?


Update - December, 15th, 2018

Google recently launched a post explaining about the so called "Badging for App Icons", which is pretty exciting:

https://developers.google.com/web/updates/2018/12/badging-api

Update - September, 28th, 2018

Relevant Links:
  • https://bugs.chromium.org/p/chromium/issues/detail?id=719176&desc=2
  • https://bugs.chromium.org/p/chromium/issues/detail?id=685159
  • https://github.com/mgiuca/badging/blob/master/explainer.md
  • https://docs.google.com/document/d/1AmX53h-gk8wN7LPMi_Mq7fsIMgsMKRD6zKa1Ymxxvvc/edit#

As Josh Lee pointed out in Is there a way to add badge notifications using progressive web apps (PWA)?, there are some discussions about the subject on the chromium team.

Looking at the discussion:

FYI, the notification indicators are being pushed to M-71.

and

Thanks for the heads up. That's fine for us because while we hope to have this testable behind a flag in M70, there's no way we'll be launching the API before (at least) M71.

So, maybe, at least for now, it seems that it's not possible to add badge notifications for PWAs, but maybe in the future we'll be able to do that.

回答1:

Looks like this is on the roadmap, possibly behind a flag in M71.

crbug.com/719176
crbug.com/685159

(So, a late October beta (schedule). There's no other activity on the bug to corroborate that, but most of the WebAPK work was not on public bugs, FWIW.)



回答2:

According to Google Developers it is a work in progress and available as an origin trial or through the flag #enable-experimental-web-platform-features on Chrome 73 and there is also a demo for Windows and MacOS.

Regarding other platforms:

Android is not supported because it requires you to show a notification, though this may change in the future.

While there is no information available regarding Safari or OSX.



回答3:

Just in case some one comes looking for answer here

It is supported now in chrome and chromium based browsers. Here are the imp Links to know more

W3C Badging API Explainer

Demo App You must install This PWA on your device

Demo App Source Code

Web.dev in short know how



回答4:

It is currently not possible to do this with PWAs. Although if developers like the feature I expect it will at some point.