鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > .net技术 > WinRT/Metro > >

重新想象 Windows 8 Store Apps (59)

来源:互联网 作者:佚名 时间:2013-12-10 13:48
重新想象 Windows 8 Store Apps (59) - 锁屏Posted on [源码下载] 重新想象 Windows 8 Store Apps (59) - 锁屏 作者:webabcd 介绍 重新想象 Windows 8 Store Apps 之锁屏 示例 1、演示如何登录锁屏,获取当前程序的锁屏权限,从锁屏中移除 LockScreen/Acces

重新想象 Windows 8 Store Apps (59) - 锁屏 Posted on

[源码下载]


重新想象 Windows 8 Store Apps (59) - 锁屏



作者:webabcd


介绍
重新想象 Windows 8 Store Apps 之 锁屏



示例
1、演示如何登录锁屏,获取当前程序的锁屏权限,,从锁屏中移除
LockScreen/AccessLockScreen.xaml

<Page x:Class="XamlDemo.LockScreen.AccessLockScreen" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:XamlDemo.LockScreen" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable

LockScreen/AccessLockScreen.xaml.cs

/* * 演示如何登录锁屏,获取当前程序的锁屏权限,从锁屏中移除 * * 注: * 要想请求锁屏权限,需要后台任务支持“推送通知”或“控制通道” */ using System; using Windows.ApplicationModel.Background; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace XamlDemo.LockScreen { AccessLockScreen : Page { public AccessLockScreen() { this.InitializeComponent(); } btnRequestAccess_Click(object sender, RoutedEventArgs e) { try { // 向系统请求登录锁屏,会弹出确认对话框 // 需要后台任务支持“推送通知”或“控制通道”,否则会抛出异常 // 不能在模拟器中运行 // 如果 BackgroundAccessStatus 不等于 Unspecified,则即使调用 RequestAccessAsync() 也不会出现对话框,需要用户去“设置”中去添加或移除锁屏应用 BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); /* * BackgroundAccessStatus - 当前 app 的锁屏权限 * Unspecified - 用户尚未选择 * Denied - 被用户拒绝 * AllowedWithAlwaysOnRealTimeConnectivity - 用于允许了,且支持实时连接,即使电量低 * AllowedMayUseActiveRealTimeConnectivity - 用于允许了,且支持实时连接,但是如果电量低则无法实时连接 */ lblMsg.Text = + status.ToString(); } catch (Exception ex) { lblMsg.Text = ex.ToString(); } } private void btnGetAccessStatus_Click(object sender, RoutedEventArgs e) { try { // 获取当前应用程序的锁屏权限 BackgroundAccessStatus status = BackgroundExecutionManager.GetAccessStatus(); lblMsg.Text = + status.ToString(); } catch (Exception ex) { lblMsg.Text = ex.ToString(); } } private void btnRemoveAccess_Click(object sender, RoutedEventArgs e) { try { // 将当前应用程序从锁屏中移除 BackgroundExecutionManager.RemoveAccess(); lblMsg.Text = ; } catch (Exception ex) { lblMsg.Text = ex.ToString(); } } } }


2、演示如何发送徽章或文本到锁屏
LockScreen/SendNotification.xaml

<Page x:Class="XamlDemo.LockScreen.SendNotification" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:XamlDemo.LockScreen" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable

LockScreen/SendNotification.xaml.cs

/* * 演示如何发送徽章或文本到锁屏 * * 注: * 如果需要发送文本到锁屏,需要手动在“设置”中将 app 添加到“选择要显示详细状态的应用”中 * * 另: * 关于 tile 和 badge 请参见:XamlDemo/Tile */ using NotificationsExtensions.BadgeContent; using NotificationsExtensions.TileContent; using Windows.UI.Notifications; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace XamlDemo.LockScreen { SendNotification : Page { public SendNotification() { this.InitializeComponent(); } private void btnSendBadge_Click(object sender, RoutedEventArgs e) { // 发送 badge 到锁屏 BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent(3); BadgeNotification badge = badgeContent.CreateNotification(); BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); badgeUpdater.Update(badge); } private void btnSendTile_Click(object sender, RoutedEventArgs e) { // 发送文本到锁屏,前提是此 app 在“选择要显示详细状态的应用”中 ITileWideSmallImageAndText03 tileContent = TileContentFactory.CreateTileWideSmallImageAndText03(); tileContent.TextBodyWrap.Text = ; tileContent.Image.Src = ; tileContent.RequireSquareContent = false; TileUpdateManager.CreateTileUpdaterForApplication().Update(tileContent.CreateNotification()); } } }


3、演示如何将一个 app 的多个 tile 绑定到锁屏
LockScreen/MultipleTiles.xaml

网友评论
<