惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
博客园 - 【当耐特】
博客园 - 三生石上(FineUI控件)
量子位
aimingoo的专栏
aimingoo的专栏
V
V2EX
Vercel News
Vercel News
B
Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News: Ask HN
Hacker News: Ask HN
TaoSecurity Blog
TaoSecurity Blog
N
News and Events Feed by Topic
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
S
Secure Thoughts
U
Unit 42
博客园 - 叶小钗
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
Help Net Security
Help Net Security
S
Security Affairs
Microsoft Security Blog
Microsoft Security Blog
W
WeLiveSecurity
博客园 - Franky
Forbes - Security
Forbes - Security
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Schneier on Security
Schneier on Security
I
InfoQ
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
Webroot Blog
Webroot Blog
AWS News Blog
AWS News Blog
Last Week in AI
Last Week in AI
Security Archives - TechRepublic
Security Archives - TechRepublic
C
CERT Recently Published Vulnerability Notes
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
Lohrmann on Cybersecurity
SecWiki News
SecWiki News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
J
Java Code Geeks

博客园 - my favorite

【转】QT样式表 (QStyleSheet) 【转】Qt事件循环与线程 二 [转]Qt 智能指针学习 【转】Android Web Server 【转】Android Http Server Java Annotation 注释语法 android中json的序列化与反序列化 JavaScript定义类的几种方式 js获取浏览器高度和宽度值(多浏览器) Setting up SSL made easy… Better, Faster, Easier SSL testing for ASP.NET MVC & WebForms ASP.NET MVC 3 Internationalization Windows 8 学习笔记(十四)--.map文件与.kml文件的解析 Windows 8学习笔记(十二)--集合控件 Windows 8 学习笔记(十三)--生命周期 Windows 8学习笔记(十一)---图片的显示与保存 Windows 8 Metro App学习笔记(九)—磁砖 Windows 8 学习笔记(八)--各种流之间的转换 Windows 8学习笔记(七)--Input输入设备
Windows 8学习笔记(十)----Notification
my favorite · 2012-07-03 · via 博客园 - my favorite

WinRT中Notification有三种类型:

Badge:徽章、标记的推送更新,主要对于磁砖进行通知

Toast:土司推送,一般是程序运行时通知

Tile:磁砖推送,自然就是程序处理休眠状态时的通知

注意:这里有消息内容都是以XML内容模板发送的

先研究下磁砖的推送Badge和Tile

Badge

了解一下有哪些方法

BadgeNotification(XmlDocument content)

BadgeUpdateManager

CreateBadgeUpdaterForApplication()---为当前应用更新磁砖

CreateBadgeUpdaterForApplication(string applicationID)---为指定的应用更新磁砖

有个疑问,这里的applicationID一般在哪儿得到??还望知道的告知一下哦~

CreateBadgeUpdaterForSecondaryTile(string tileID)—为指定的磁砖更新

GetTemplateContent(BadgeTemplateType type)—获取预定义好的XML徽章模板

BadgeUpdater

Update(BadgeNotification notification)

示例代码:

XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);

XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");

 // We are setting attribute value 6

badgeElement.SetAttribute("value", "6");

// Create a badge notification from XML

BadgeNotification badgeNotification = new BadgeNotification(badgeXml);

// Send the notification to the secondary tile

 BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(MainPage.dynamicTileId);

 badgeUpdater.Update(badgeNotification);

Tile

它包含的方法跟Badge类似

TileNotification(XmlDocument document)

TileUpdateManager

包手中四个方法,跟BadgeUpdateManager类似

CreateTileUpdaterForApplication()

CreateTileUpdaterForApplication(string applicationID)

CreateTileUpdaterForSecondaryTile(string tileID)

GetTemplateContent

TileUpdater--Update(TileNotificaton notification)

示例代码:

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 in

XmlNodeList 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 XML

TileNotification tileNotification = new TileNotification(tileXml);

 // Send the notification to the secondary tile by creating a secondary tile updater

TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(MainPage.dynamicTileId);

tileUpdater.Update(tileNotification);

Toast

方法和属性也基本类似

但我下面的代码有问题,没有显示Toast通知,注册Failed事件,跟踪说是应用程序功能会阻止通知传递。 (异常来自 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();

在MSDN Sample里有Toast Sample示例,里面封装了NotificationExtensions扩展,很容易就可以实现通知更新,不需要编辑复杂的XML模板,但很纠结,我上面的代码有啥问题??

NotificationsExtensions微软示例给我们封装的类库,非常方便,得学习一下大师的封装逻辑。。。

磁砖的更新还算简单,PushNotification有点摸不着头脑,首先PushChannel都是要手动输入,这个不是生成的么,很纠结,还希望有研究的同胞能提供点学习资料,跟Phone7的机制不太一样呢?!

TrackBack:

http://www.cnblogs.com/jing870812/archive/2012/04/17/2454511.html