Windows 8 Study Notes (10) -- Notification

Source: Internet
Author: User

In winrt, there are three types of notification:

Badge: Badges and tags are pushed and updated, mainly for tile notifications

Toast: Tusi push, usually a notification when the program is running

Tile: Tile push, which is naturally a notification when the program processes the sleep state

Note: The message content here is sent using an XML content template.

First, we will study the push badge and tile of tile.

Badge

How can this problem be solved?

Badgenotification (xmldocument content)

Badgeupdatemanager

Createbadgeupdaterforapplication () --- Update tile for the current application

Createbadgeupdaterforapplication (string applicationid) --- Update tile for the specified application

Where can I find the applicationid here ?? I hope you can tell me what you know ~

Createbadgeupdaterforsecondarytile (string tileid)-update the specified Tile

Gettemplatecontent (badgetemplatetype type)-Get the predefined XML badge Template

Badgeupdater

Update (badgenotification notification)

Sample Code:

XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge"); // We are setting attribute value 6badgeElement.SetAttribute("value", "6");// Create a badge notification from XMLBadgeNotification badgeNotification = new BadgeNotification(badgeXml);// Send the notification to the secondary tile BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(MainPage.dynamicTileId); badgeUpdater.Update(badgeNotification);

 

Tile

The method is similar to that of badge.

Tilenotification (xmldocument document)

Tileupdatemanager

Four methods in the package, similar to badgeupdatemanager

Createtileupdaterforapplication ()

Createtileupdaterforapplication (string applicationid)

Createtileupdaterforsecondarytile (string tileid)

Gettemplatecontent

Tileupdater -- Update (tilenotificaton notification)

Sample Code:

XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideText04);// Refer to template documentation to determine how many text fields a particular template has // get the text attributes for this template and fill them inXmlNodeList tileTextElements = tileXml.GetElementsByTagName("text");tileTextElements.Item(0).AppendChild(tileXml.CreateTextNode("Sent to a secondary tile!"));XmlDocument squareTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquareText04);XmlNodeList squareTileTextElements = squareTileXml.GetElementsByTagName("text");squareTileTextElements.Item(0).AppendChild(squareTileXml.CreateTextNode("Sent to a secondary tile!")); // Include the square template in the notification IXmlNode subNode = tileXml.ImportNode(squareTileXml.GetElementsByTagName("binding").Item(0), true); tileXml.GetElementsByTagName("visual").Item(0).AppendChild(subNode);// Create the notification from the XMLTileNotification tileNotification = new TileNotification(tileXml); // Send the notification to the secondary tile by creating a secondary tile updaterTileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(MainPage.dynamicTileId);tileUpdater.Update(tileNotification);
 

Toast

Methods and attributes are similar.

However, my code below has a problem and does not display the toast notification. register the failed event and the tracing says that the application function will block notification delivery. (Exception from hresult: 0x803e0112)

XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);XmlNodeList textNodes = toastXml.GetElementsByTagName("text"); textNodes.Item(0).AppendChild(toastXml.CreateTextNode("Sent to Toast Notification!"));ToastNotification toastNotification = new ToastNotification(toastXml);toastNotification.Failed += toastNotification_Failed;toastNotification.Dismissed += toastNotification_Dismissed;ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();

There is a toast sample in the msdn sample, which encapsulates the icationicationextensions extension, which can easily implement notification updates without editing complicated XML templates, what is the problem with the above Code ??

Icationicationsextensions the class library encapsulated by Microsoft is very convenient. You have to learn the encapsulation logic of the master...

The update of tile is simple, and pushnotification is a bit confusing. First of all, pushchannel requires manual input. Isn't it generated? It's hard to understand. I also hope that students from research can provide some learning materials, isn't the same mechanism as phone7 ?!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.