我有一个Windows Phone 8应用程序,我最近升级到8.1 Silverlight。我想使用新的图块模板。现在我有一个使用ShellTile的ScheduledTaskAgent。Windows Phone 8.1活动平铺后台任务
为了使用新的实时切片,我在WMAppManifest.xml中将通知服务更改为WNS。我删除了代码以注册旧的后台任务,并将此代码来代替:
var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();
if (backgroundAccessStatus == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity ||
backgroundAccessStatus == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
{
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
if (task.Value.Name == "LiveTileBackgroundTask")
{
task.Value.Unregister(true);
}
}
BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
taskBuilder.Name = "LiveTileBackgroundTask";
taskBuilder.TaskEntryPoint = "BackgroundTasks.LiveTileBackgroundTask";
taskBuilder.SetTrigger(new TimeTrigger(15, false));
var registration = taskBuilder.Register();
}
我创建了Windows Phone 8.1的Windows运行时组件称为BackgroundTasks
包含BackgroundTask称为LiveTileBackgroundTask
:
public sealed class LiveTileBackgroundTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
const string xml = "<tile>"
+ "<visual>"
+ "<binding template='TileWideText01'>"
+ "<text id='1'>Text Field 1 (larger text)</text>"
+ "<text id='2'>Text Field 2</text>"
+ "<text id='3'>Text Field 3</text>"
+ "<text id='4'>Text Field 4</text>"
+ "<text id='5'>Text Field 5</text>"
+ "</binding> "
+ "</visual>"
+"</tile>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
TileNotification tileNotification = new TileNotification(doc);
TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
deferral.Complete();
}
}
我加在我的Windows Phone项目中对此程序集的引用。
我还在我的Package.appxmanifest中添加了后台任务声明,它具有BackgroundTasks.LiveTileBackgroundTask
作为入口点。我选择了定时器和系统事件作为支持的任务类型。
当我运行应用程序,但没有任何反应。不显示活动磁贴。我跑过后台任务,一切都顺利,没有任何例外。
嗨,你尝试只更新前景瓷砖而不是后台任务?我问的原因是因为我甚至无法在前台更新磁贴... –
嗨,我试过了,它也没有工作。 –
请看看这一个http:// stackoverflow。com/questions/23589479/new-live-tiles-dont-work-in-windows-phone-silverlight-8-1-apps –