Skip to content

Commit a8dae5a

Browse files
SatwikKrSharmaSatwik Kumar Sharmajonwis
authored
API Spec for Badge Notifications in WindowsAppSdk (#4823)
* API Spec for Badge Notifications in WindowsAppSdk * fixed typo * resolved PR comments * Pretty-print markdown * resolved PR comments and added compatibility section in the spec * resolved API spec review comments * resolved nit comment * Added clarification for None Glyph Type * Formatting pass, packaging note * Update BadgeNotifications-spec.md --------- Co-authored-by: Satwik Kumar Sharma <satwiksharma@microsoft.com> Co-authored-by: Jon Wiswall <jonwis@microsoft.com>
1 parent a4f2707 commit a8dae5a

15 files changed

Lines changed: 204 additions & 0 deletions
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# Badge Notifications in Windows App SDK
2+
3+
This is the spec for proposal: [Issue #138](https://github.com/microsoft/WindowsAppSDK/issues/138)
4+
5+
# Background
6+
7+
A notification badge conveys summary or status information specific to your app. They can be numeric
8+
(1-99) or one of a set of system-provided glyphs. Examples of information best conveyed through a
9+
badge include network connection status in an online game, user status in a messaging app, number of
10+
unread mails in a mail app, and number of new posts in a social media app.
11+
12+
Example of a numeric badge in Taskbar (One new message in Whatsapp):
13+
14+
![Screenshot](NumericBadgeExample.png)
15+
16+
Example of a system-provided glyph in taskbar (New message in Outlook):
17+
18+
![Screenshot](GlyphBadgeExample.png)
19+
20+
This Badge notification functionality is missing in WinAppSDK, which not only blocks apps like
21+
WhatsApp to move to WinAppSDK but also stops them from availing new features and goodness that we
22+
are building in WinAppSDK. The scope of this document is to fill that gap and provide badge
23+
notification capability in WinAppSDK as well.
24+
25+
> Note: This provids a subset of functionality present in WindowsSdk, but all that is necessary to
26+
> post and clear a badge notification
27+
28+
# Description
29+
30+
Badge notifications provide users with a visual indicator of new or important content in your
31+
application. This feature enhances user engagement by allowing them to quickly see updates without
32+
needing to open the app. Badge notifications are already supported for UWP apps. This initiative is
33+
to make badge notifications work in WindowsAppSdk.
34+
35+
For more details see:
36+
37+
- [Badge Notification WinRT APIs](https://learn.microsoft.com/windows/apps/design/shell/tiles-and-notifications/badges)
38+
Defines all the API constructs that we have for Badge Notifications in WinRT today.
39+
40+
# Compatibility
41+
42+
## Supported Apps
43+
44+
This API requires package identity to match notifications to applications. See
45+
[an overview of package identity](https://learn.microsoft.com/windows/apps/desktop/modernize/package-identity-overview)
46+
for how to deploy your application as a package, or assign identity to your existing application
47+
during its install time.
48+
49+
## Notification Type
50+
51+
The badge notifications are local to the device. No remote server interaction is required or
52+
supported for updating the badge count.
53+
54+
# Examples
55+
56+
## Create a numeric badge (c++)
57+
58+
```c++
59+
private void setBadgeNumber(uint32_t num)
60+
{
61+
winrt::BadgeNotificationManager manager = winrt::BadgeNotificationManager::Current();
62+
manager.SetBadgeAsCount(num);
63+
}
64+
```
65+
66+
## Create a Glyph badge (c++)
67+
68+
```c++
69+
private void updateBadgeGlyph()
70+
{
71+
winrt::BadgeNotificationGlyph badgeNotificationGlyph = winrt::BadgeNotificationGlyph::Alert;
72+
winrt::BadgeNotificationManager manager = winrt::BadgeNotificationManager::Current();
73+
manager.SetBadgeAsGlyph(badgeNotificationGlyph);
74+
}
75+
```
76+
77+
## Clear a badge
78+
79+
```c++
80+
private void clearBadge()
81+
{
82+
winrt::BadgeNotificationManager manager = winrt::BadgeNotificationManager::Current();
83+
manager.ClearBadge();
84+
}
85+
```
86+
87+
## To set an expiration time in a badge (c++)
88+
89+
```c++
90+
private void updateBadgeGlyph()
91+
{
92+
winrt::BadgeNotificationGlyph badgeNotificationGlyph = winrt::BadgeNotificationGlyph::Alert
93+
94+
DateTime expirationTime = clock::now() + std::chrono::hours(24);
95+
96+
winrt::BadgeNotificationManager manager = winrt::BadgeNotificationManager::Current();
97+
manager.SetBadgeAsGlyph(badgeNotificationGlyph, expirationTime);
98+
}
99+
```
100+
101+
# API Description
102+
103+
## BadgeNotificationManager class
104+
105+
The `BadgeNotificationManager` class is the central point for managing badge notifications for an
106+
application. It provides the functionality to update or clear the badge displayed on the app's tile.
107+
This class allows developers to modify the badge's appearance by setting a numeric value or a glyph
108+
and also to remove the badge when it is no longer needed.
109+
110+
## BadgeNotificationManager Properties
111+
112+
| Name | Description | Type |
113+
| ------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------ |
114+
| Current | Provides a default instance of the `BadgeNotificationManager` for use in updating or clearing badge notifications. | BadgeNotificationManager |
115+
116+
## BadgeNotificationManager Methods
117+
118+
| Name | Description | Parameters | Returns |
119+
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ------- |
120+
| SetBadgeAsCount | Updates the badge on the app's tile to display a numeric value. This method is used to reflect a new status or count. | UInt32 `notificationCount` | void |
121+
| SetBadgeAsCount | Updates the badge on the app's tile to display a numeric value, with an expiration time after which the badge should be cleared. | UInt32 `notificationCount`, Windows.Foundation.DateTime `expiration` | void |
122+
| SetBadgeAsGlyph | Updates the badge on the app's tile to display a glyph. This method is used to reflect a new status represented by a glyph. | BadgeNotificationGlyph `glyphValue` | void |
123+
| SetBadgeAsGlyph | Updates the badge on the app's tile to display a glyph, with an expiration time after which the badge should be cleared. | BadgeNotificationGlyph `glyphValue`, Windows.Foundation.DateTime `expiration` | void |
124+
| ClearBadge | Removes the badge notifications for the app from the action center. This method is useful for clearing any badge notifications when they are no longer relevant or when the app wants to reset its badge status. | | void |
125+
126+
> Note: For Numeric badge if the count is greater then 99 it will be reported as "99+"
127+
128+
## BadgeNotificationGlyph enum
129+
130+
The `BadgeNotificationGlyph` enum defines a set of predefined glyphs that can be used to represent
131+
various statuses or notifications on an application's badge. These glyphs provide a visual cue on
132+
the app's tile, allowing users to quickly understand the app's status or to be alerted to new
133+
information without opening the app.
134+
135+
| Name | Description | Glyph |
136+
| ----------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------ |
137+
| None | No glyph is displayed. The badge will not be shown at all. It is equivalent to ClearBadge. | (No Badge Shown) |
138+
| Activity | A glyph indicating some form of activity is taking place within the app. | ![Screenshot](badge-activity.png) |
139+
| Alarm | A glyph that represents an alarm, possibly indicating a set reminder or a timed event. | ![Screenshot](badge-alarm.png) |
140+
| Alert | A glyph that suggests an alert or an important notification that may require immediate attention. | ![Screenshot](badge-alert.png) |
141+
| Attention | A glyph that signifies the need for attention, often used for notifications or new information. | ![Screenshot](badge-attention.png) |
142+
| Available | A glyph that indicates the user or a service is available, often used in communication apps. | ![Screenshot](badge-available.png) |
143+
| Away | A glyph that shows the user is away or inactive, commonly used in status indicators for communication apps. | ![Screenshot](badge-away.png) |
144+
| Busy | A glyph that represents the user being busy or engaged in an activity, preventing interruptions. | ![Screenshot](badge-busy.png) |
145+
| Error | A glyph that denotes an error has occurred, which may require user action to resolve. | ![Screenshot](badge-error.png) |
146+
| NewMessage | A glyph that indicates the arrival of a new message, often used in messaging and email applications. | ![Screenshot](badge-newmessage.png) |
147+
| Paused | A glyph that signifies a pause in activity or content, such as media playback being paused. | ![Screenshot](badge-paused.png) |
148+
| Playing | A glyph that indicates media or content is currently playing. | ![Screenshot](badge-playing.png) |
149+
| Unavailable | A glyph that shows the user or a service is not currently available or offline. | ![Screenshot](badge-unavailable.png) |
150+
151+
These glyphs are system-provided and standardized, ensuring a consistent look and feel across
152+
different applications that use them. By using these glyphs, developers can convey specific states
153+
or notifications to users in a visually intuitive manner.
154+
155+
> Note: Only system-provided badge images can be used.
156+
157+
# API Details
158+
159+
> Note: all of this new WinAppSDK API is to support Badge Notifications in WindowsAppSdk
160+
161+
```c++ (but really MIDL3)
162+
namespace Microsoft.Windows.BadgeNotifications
163+
{
164+
// Set of predefined glyphs that can be used to represent various statuses or notifications on an application's badge
165+
enum BadgeNotificationGlyph
166+
{
167+
None, // No glyph. A blank tile appears in the badge.
168+
Activity, // A glyph representing an activity
169+
Alarm, // A glyph representing an alarm
170+
Alert, // A glyph representing an alert
171+
Attention, // A glyph representing attention
172+
Available, // A glyph representing availability
173+
Away, // A glyph representing being away
174+
Busy, // A glyph representing being busy
175+
Error, // A glyph representing an error
176+
NewMessage, // A glyph representing a new message
177+
Paused, // A glyph representing being paused
178+
Playing, // A glyph representing playing
179+
Unavailable, // A glyph representing being unavailable
180+
};
181+
182+
// The manager class which encompasses all Badge Notification API Functionality
183+
runtimeclass BadgeNotificationManager
184+
{
185+
// Gets a Default instance of a BadgeNotificationManager
186+
static BadgeNotificationManager Current{ get; };
187+
188+
// Updates the badge on the app's icon on taskbar to display a numeric value.
189+
void SetBadgeAsCount(UInt32 notificationCount);
190+
191+
// Updates the badge on the app's icon on taskbar to display a numeric value with an expiration time.
192+
void SetBadgeAsCount(UInt32 notificationCount, Windows.Foundation.DateTime expiration);
193+
194+
// Updates the badge on the app's icon on taskbar to display a glyph.
195+
void SetBadgeAsGlyph(BadgeNotificationGlyph glyphValue);
196+
197+
// Updates the badge on the app's icon on taskbar to display a glyph with an expiration time.
198+
void SetBadgeAsGlyph(BadgeNotificationGlyph glyphValue, Windows.Foundation.DateTime expiration);
199+
200+
// Removes the Badge Notifications for the App from Action Center
201+
void ClearBadge();
202+
}
203+
}
204+
```
3.77 KB
Loading
3.32 KB
Loading
2.42 KB
Loading
1.95 KB
Loading
2.24 KB
Loading
1.39 KB
Loading
2.07 KB
Loading
2.04 KB
Loading
2.06 KB
Loading

0 commit comments

Comments
 (0)