快速构建Windows 8风格应用33-构建锁屏提醒

引言
Windows Phone(8&7.5)和Windows 8引入了锁屏概念,其实做过Windows Phone 7.5应用开发者都知道7.5时代手机锁屏是不支持第三方开发者开发的。那么现在我们第三方开发者可以在Windows 8和Windows Phone 8的锁屏界面开发显示自己应用的信息了。
Windows 8 锁屏具有三种用途:
- 防止触控设备上的意外登录尝试;
- 为用户提供个性化的界面;
- 向用户显示精简的信息:日期和时间、网络状态和电池状态、来自有限个应用的通知;

一、锁屏提醒概览
Windows 8的锁屏上一次最多可显示 7 个应用。这 7 个应用都可以显示锁屏提醒和 Toast,但只允许其中一个应用显示其最新磁贴通知的文本。

我们可以在“电脑设置”中来添加要显示在锁屏上的应用。
关于锁屏更多详细信息可参考:锁屏概述(Windows 应用商店应用) (Windows)。
二、构建应用锁屏提醒
锁屏提醒是显示在磁贴右下角(或左下角)的数字或字形,通常用来指示应用状态。
锁屏提醒是磁贴上的重叠,而不是磁贴本身的一部分,另外锁屏提醒可以通过相关通知进行更新。
那么我们如何声明一个简单的应用锁屏提醒呢?
1.配置应用清单文件
- “应用程序UI”选项卡中选择“徽章徽标”,选择“锁定屏幕通知”,指定“徽章徽标”。

- “声明”选择卡中添加“后台任务“,选择”支持的任务类型“(注意:具有锁屏应用必须声明”控制通道“、”计时器“、”推送通知“三种后台任务类型之一),设置”应用程序设置“。

2.添加命名空间
1: using Windows.UI.Notifications;
2: using Windows.Data.Xml.Dom;
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
其中Windows.UI.Notifications 包含了锁屏提醒 API。
3.选择锁屏提醒上显示数字或字形
锁屏提醒可以显示数字 0-99 或系统定义的状态字形集。
显示数字:
1: XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }或显示字形:
1: XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph);
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
4.为锁屏应用分配值
分配数字值:
1: XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
2: badgeElement.SetAttribute("value", "7");
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
或分配字形值:
1: XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
2: badgeElement.SetAttribute("value", "newMessage");
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
5.创建锁屏提醒通知并将其发送到锁屏提醒
将我们定义好的xml发送到锁屏提醒。
1: BadgeNotification badge = new BadgeNotification(badgeXml);
2: BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
最后,我们也可以通过BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear()方法将锁屏提醒清除,另外锁屏提醒可以通过云清除。
通过以上几个步骤我们就可以出一个应用的锁屏提醒。
更多关于构建锁屏提醒的资料可参考:
- 快速入门:发送锁屏提醒更新(使用 C#/VB/C++ 和 XAML 的 Windows 应用商店应用) (Windows)
- 快速入门:在锁屏上显示磁贴和锁屏提醒更新(Windows 应用商店应用) (Windows)
三、锁屏提醒最佳实践
因为微软官方给到我们开发者非常详细的关于锁屏提醒最佳实践的方法,这里我简单提及一下。
例如:当应用在锁屏提醒上显示的是数字,并且该数字会大于50,那么我们推荐使用系统字形类型。
更详细关于锁屏提醒最佳实践的资料可参考:磁贴和锁屏提醒指南和清单(Windows 应用商店应用) (Windows)。
快速构建Windows 8风格应用33-构建锁屏提醒的更多相关文章
- 快速构建Windows 8风格应用15-ShareContract构建
原文:快速构建Windows 8风格应用15-ShareContract构建 本篇博文主要介绍共享数据包.如何构建共享源.如何构建共享目标.DataTransferManager类. 共享数据包 Da ...
- 快速构建Windows 8风格应用13-SearchContract构建
原文:快速构建Windows 8风格应用13-SearchContract构建 本篇博文主要介绍如何在应用中构建SearchContract,相应的原理已经在博文<快速构建Windows 8风格 ...
- 快速构建Windows 8风格应用32-构建辅助磁贴
原文:快速构建Windows 8风格应用32-构建辅助磁贴 引言 Windows Phone中,我们开发者可能会开发的一个功能点是将数据列表中某一项"Pin To Start(固定到开始屏幕 ...
- 快速构建Windows 8风格应用17-布局控件
原文:快速构建Windows 8风格应用17-布局控件 本篇博文主要介绍三种常用的布局控件:Canvas.Grid.StackPanel. Panel类是开发Windows 8 Store应用中一个重 ...
- 快速构建Windows 8风格应用14-ShareContract概述及原理
原文:快速构建Windows 8风格应用14-ShareContract概述及原理 本篇博文主要介绍Share Contract概述.Share Contract实现原理.实现Share Contra ...
- 快速构建Windows 8风格应用9-竖直视图
原文:快速构建Windows 8风格应用9-竖直视图 本篇博文主要介绍竖直视图概览.关于竖直视图设计.如何构建竖直视图 竖直视图概览 Windows 8为了支持旋转的设备提供了竖屏视图,我们开发的应用 ...
- 快速构建Windows 8风格应用10-设备方向
原文:快速构建Windows 8风格应用10-设备方向 本篇博文主要介绍常用支持Windows 8操作系统设备的方向.如何获取当前设备方向.DisplayProperties类. 常用支持Window ...
- 快速构建Windows 8风格应用11-语义缩放
原文:快速构建Windows 8风格应用11-语义缩放 本篇博文主要介绍为什么需要语义缩放.什么是语义缩放.如何构建语义缩放. 为什么需要语义缩放 如果用过Windows 8系统的开发者都知道在Win ...
- 快速构建Windows 8风格应用12-SearchContract概述及原理
原文:快速构建Windows 8风格应用12-SearchContract概述及原理 本篇博文主要介绍Search Contract概述.Search Contract面板结构剖析.Search Co ...
随机推荐
- Tri_integral Summer Training 5 总结
比赛 题目 B D E G H I J 这是泰国的一场区域赛,除了C题英语非常抽以外,其余题目还不算难读. 一开场就发现了三道很水的题目,0:21:34就把三道题给过了,都是1A,赞Moor的手速. ...
- SQL 2008执行语句遇到内存不足(1)——error 701
原文:SQL 2008执行语句遇到内存不足(1)--error 701 转自:http://blogs.msdn.com/b/apgcdsd/archive/2011/01/17/sql-2008-e ...
- ios save image to album
- (void)savePhotoToAlbum { ZoomScrollView *zoomScrollView = (ZoomScrollView*)[self.scrollView viewWi ...
- 阿里云ECSserver部署django
highlight=uwsgi%20django">參考 server安装的是Centos 系统. uwsgi是使用pip安装的. nginx是使用yum install nginx安 ...
- M、V、C
概述 Model-View-Controller(MVC),即模型-视图-控制器. MVC将软件系统分成三大部分:Model,View,Controller,三个部分通过某种机制通信 M.V.C的职能 ...
- IIS 7.0 Features and Vista Editions
原文 IIS 7.0 Features and Vista Editions Overview of IIS 7.0 differences Across Windows Vista Editions ...
- JavaEE(11) - 消息驱动EJB
1. MDB作为异步消费者的本质 2. MDB的运行机制 3. 使用@MessageDriven修饰MDB(需要messageListenerInterface) 4. 实现MessageListen ...
- Pro Aspnet MVC 4读书笔记(5) - Essential Tools for MVC
Listing 6-1. The Product Model Class using System; using System.Collections.Generic; using System.Li ...
- SQL Server的还原
原文:SQL Server的还原 1.差异备份的还原 不备份结尾日志的情况下还原数据 创建差异备份的放在我们已经在前面一篇博客SQL Server的备份中提到了,这里我们不再赘述,下面我们给出差异备份 ...
- (两)unity4.6Ugui中国教程文档-------总结-UGUI Canvas
大家好,我是广东太阳. 转载请注明出处:http://write.blog.csdn.net/postedit/38922399 更全的内容请看我的游戏蛮牛地址:http://www.unitym ...