ToastNotificationManager
ToastNotificationManager
ToastNotificationManager
ToastNotificationManager
Class
Definition
Creates ToastNotifier objects that you use to raise toast notifications. This class also provides access to the XML content of the system-provided toast templates so that you can customize that content for use in your notifications.
public : static class ToastNotificationManagerpublic static class ToastNotificationManagerPublic Static Class ToastNotificationManager// You can use this class in JavaScript.
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Examples
The following example shows how to create and send a toast notification that includes text and images, including the use of the GetTemplateContent and CreateToastNotifier methods.
var notifications = Windows.UI.Notifications;
// Get the toast notification manager for the current app.
var notificationManager = notifications.ToastNotificationManager;
// The getTemplateContent method returns a Windows.Data.Xml.Dom.XmlDocument object
// that contains the toast notification XML content.
var template = notifications.toastTemplateType.toastImageAndText01;
var toastXml = notificationManager.getTemplateContent(notifications.ToastTemplateType[template]);
// You can use the methods from the XML document to specify the required elements for the toast.
var images = toastXml.getElementsByTagName("image");
images[0].setAttribute("src", "images/toastImageAndText.png");
var textNodes = toastXml.getElementsByTagName("text");
textNodes.forEach(function (value, index) {
var textNumber = index + 1;
var text = "";
for (var j = 0; j < 10; j++) {
text += "Text input " + /*@static_cast(String)*/textNumber + " ";
}
value.appendChild(toastXml.createTextNode(text));
});
// Create a toast notification from the XML, then create a ToastNotifier object
// to send the toast.
var toast = new notifications.ToastNotification(toastXml);
notificationManager.createToastNotifier().show(toast);
Remarks
Sending toast notifications from desktop apps
Generally, sending a toast notification from a desktop app is the same as sending it from a Windows Store app. However, you should be aware of these differences and requirements:
- For a desktop app to display a toast, the app must have a shortcut on the Start screen.
- The shortcut must have an AppUserModelID.
- Desktop apps cannot schedule a toast.
For more information, see these topics:
- How to enable desktop toast notifications through an AppUserModelID
- Quickstart: Sending a toast notification from the desktop
Properties
History History History History
Gets the ToastNotificationHistory object.
public : static ToastNotificationHistory History { get; }public static ToastNotificationHistory History { get; }Public Static ReadOnly Property History As ToastNotificationHistory// You can use this property in JavaScript.
Methods
ConfigureNotificationMirroring(NotificationMirroring) ConfigureNotificationMirroring(NotificationMirroring) ConfigureNotificationMirroring(NotificationMirroring) ConfigureNotificationMirroring(NotificationMirroring)
Specifies whether notification mirroring is allowed. Notification mirroring enables a notification to be broadcast on multiple devices.
public : static void ConfigureNotificationMirroring(NotificationMirroring value)public static void ConfigureNotificationMirroring(NotificationMirroring value)Public Static Function ConfigureNotificationMirroring(value As NotificationMirroring) As void// You can use this method in JavaScript.
One of the enumeration values.
| Device family |
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v3)
|
CreateToastNotifier() CreateToastNotifier() CreateToastNotifier() CreateToastNotifier()
Creates and initializes a new instance of the ToastNotification, bound to the calling application, that lets you raise a toast notification to that app.
public : static ToastNotifier CreateToastNotifier()public static ToastNotifier CreateToastNotifier()Public Static Function CreateToastNotifier() As ToastNotifier// You can use this method in JavaScript.
The object you will use to send the toast notification to the app.
Examples
The following example shows how to create and send a toast notification that includes text and images, including the use of the CreateToastNotifier method.
var notifications = Windows.UI.Notifications;
// Get the toast notification manager for the current app.
var notificationManager = notifications.ToastNotificationManager;
// The getTemplateContent method returns a Windows.Data.Xml.Dom.XmlDocument object
// that contains the toast notification XML content.
var template = notifications.toastTemplateType.toastImageAndText01;
var toastXml = notificationManager.getTemplateContent(notifications.ToastTemplateType[template]);
// You can use the methods from the XML document to specify the required elements for the toast.
var images = toastXml.getElementsByTagName("image");
images[0].setAttribute("src", "images/toastImageAndText.png");
var textNodes = toastXml.getElementsByTagName("text");
textNodes.forEach(function (value, index) {
var textNumber = index + 1;
var text = "";
for (var j = 0; j < 10; j++) {
text += "Text input " + /*@static_cast(String)*/textNumber + " ";
}
value.appendChild(toastXml.createTextNode(text));
});
// Create a toast notification from the XML, then create a ToastNotifier object
// to send the toast.
var toast = new notifications.ToastNotification(toastXml);
notificationManager.createToastNotifier().show(toast);
Remarks
Do not use this overload when creating a toast notifier for a desktop app. Use CreateToastNotifier(appID) to supply the required AppUserModelID.
If your app uses a background voice-over-Internet protocol (VOIP) agent, it must specify the app ID to show a toast. Use the CreateToastNotifier(appID) method overload.
CreateToastNotifier(String) CreateToastNotifier(String) CreateToastNotifier(String) CreateToastNotifier(String)
Creates and initializes a new instance of the ToastNotification, bound to a specified app, usually another app in the same package.
public : static ToastNotifier CreateToastNotifier(PlatForm::String applicationId)public static ToastNotifier CreateToastNotifier(String applicationId)Public Static Function CreateToastNotifier(applicationId As String) As ToastNotifier// You can use this method in JavaScript.
- applicationId
- PlatForm::String String String String
The unique ID of the app.
Note
You can't send a toast notification to a secondary tile, so this must be the ID of an app tile.
The object you will use to send the toast notification to the tile.
Remarks
The app identified by applicationId must belong to the same package as the caller.
Use this form of the method if your app uses a background voice-over-Internet protocol (VOIP) agent, to specify the app ID required to show a toast in that case.
Sending toast notifications from desktop apps
Generally, sending a toast notification from a desktop app is the same as sending it from a Windows Store app. However, you should be aware of these differences and requirements:
- For a desktop app to display a toast, the app must have a shortcut on the Start screen.
- The shortcut must have an AppUserModelID.
- Desktop apps cannot schedule a toast.
For more information, see these topics:
- How to enable desktop toast notifications through an AppUserModelID
- Quickstart: Sending a toast notification from the desktop
- See Also
-
GetDefault() GetDefault() GetDefault() GetDefault()
Gets a toast notification manager for the current user.
public : static ToastNotificationManagerForUser GetDefault()public static ToastNotificationManagerForUser GetDefault()Public Static Function GetDefault() As ToastNotificationManagerForUser// You can use this method in JavaScript.
A toast notification manager for the current user.
| Device family |
Windows 10 Creators Update (introduced v10.0.15063.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v4)
|
GetForUser(User) GetForUser(User) GetForUser(User) GetForUser(User)
Gets a toast notification manager for the specified user.
public : static ToastNotificationManagerForUser GetForUser(User user)public static ToastNotificationManagerForUser GetForUser(User user)Public Static Function GetForUser(user As User) As ToastNotificationManagerForUser// You can use this method in JavaScript.
A object for creating toast notifications for the specified user.
| Device family |
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v3)
|
GetTemplateContent(ToastTemplateType) GetTemplateContent(ToastTemplateType) GetTemplateContent(ToastTemplateType) GetTemplateContent(ToastTemplateType)
Gets the XML content of one of the predefined toast templates so that you can customize it for use in your notification.
public : static XmlDocument GetTemplateContent(ToastTemplateType type)public static XmlDocument GetTemplateContent(ToastTemplateType type)Public Static Function GetTemplateContent(type As ToastTemplateType) As XmlDocument// You can use this method in JavaScript.
One of the system-provided toast templates.
The object that contains the template XML.
Examples
The following example shows how to create and send a toast notification that includes text and images, including the use of the GetTemplateContent method.
var notifications = Windows.UI.Notifications;
// Get the toast notification manager for the current app.
var notificationManager = notifications.ToastNotificationManager;
// The getTemplateContent method returns a Windows.Data.Xml.Dom.XmlDocument object
// that contains the toast notification XML content.
var template = notifications.toastTemplateType.toastImageAndText01;
var toastXml = notificationManager.getTemplateContent(notifications.ToastTemplateType[template]);
// You can use the methods from the XML document to specify the required elements for the toast.
var images = toastXml.getElementsByTagName("image");
images[0].setAttribute("src", "images/toastImageAndText.png");
var textNodes = toastXml.getElementsByTagName("text");
textNodes.forEach(function (value, index) {
var textNumber = index + 1;
var text = "";
for (var j = 0; j < 10; j++) {
text += "Text input " + /*@static_cast(String)*/textNumber + " ";
}
value.appendChild(toastXml.createTextNode(text));
});
// Create a toast notification from the XML, then create a ToastNotifier object
// to send the toast.
var toast = new notifications.ToastNotification(toastXml);
notificationManager.createToastNotifier().show(toast);
Remarks
Instead of creating the full XML payload yourself, you can get a template and then use Document Object Model (DOM) manipulation functions to customize the part of the content that you want to change. You package this XML in a ToastNotification and send it to the tile through the ToastNotifier that you create through the other methods of this class.
See tile schema for an explanation of tile elements and attributes.
- See Also
-
See Also
- Toast notifications sample
- Sending toast notifications from desktop apps sample
- Toast XML schema
- Toast notification overview
- Quickstart: Sending a toast notification
- Quickstart: Sending a toast push notification
- Quickstart: Sending a toast notification from the desktop
- Guidelines and checklist for toast notifications
- How to handle activation from a toast notification
- How to opt in for toast notifications
- How to schedule a toast notification
- How to enable desktop toast notifications through an AppUserModelID
- The toast template catalog
- Toast audio options