1

我有一个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作为入口点。我选择了定时器和系统事件作为支持的任务类型。

当我运行应用程序,但没有任何反应。不显示活动磁贴。我跑过后台任务,一切都顺利,没有任何例外。

+0

嗨,你尝试只更新前景瓷砖而不是后台任务?我问的原因是因为我甚至无法在前台更新磁贴... –

+0

嗨,我试过了,它也没有工作。 –

+0

请看看这一个http:// stackoverflow。com/questions/23589479/new-live-tiles-dont-work-in-windows-phone-silverlight-8-1-apps –

回答

1

连续后台执行,不支持的Silverlight 8.1 应用

的Windows Phone 8级的应用程序可以继续 用户导航在一定条件下的应用走在后,在后台运行。这个 功能不适用于Silverlight 8.1应用程序。如果你需要这个 功能,你应该继续使用Windows Phone 8应用程序。欲了解更多 信息,请参阅在后台运行定位追踪应用的 的Windows Phone 8

Platform compatibility and breaking changes for Windows Phone Silverlight 8.1 apps

的Windows Phone 8.1的Windows运行时组件只能随着Windows Phone 8.1运行时(商店)的应用程序中使用

+0

这不是这个。这不是一个“连续的背景”任务,它只是一个正常的后台任务,应该定期执行。它只是这样做的,但瓦片不会更新。如果它不兼容,它将无法编译。 我应该可以在WP8.1 Silverlight中使用新的图块模板,但是我不认为它们会使用旧的ScheduledTaskAgent。 –

+1

在批评之前,最好先阅读链接中的内容,然后再看下一段。您是否将旧的ScheduledTaskAgent升级到8.1?并且从使用Windows Phone 8.1运行时组件的Windows Phone Silverlight 8.1应用程序这个概念开始......这同样是“我希望使用新的平铺模板”,而这只适用于RT平台对于Silverlight – IceFog

+0

“仅适用于RT平台不适用于Silverlight” - >抱歉,但事实并非如此。 Microsoft内的多个人员明确确认WP8.1 SL_can_使用新的切片模板。 –

3

你说“没有活动瓷砖出现”。您发布的代码不会创建实时平铺 - 它只会更新一个。您必须手动固定它 - 主代码不能通过代码固定。

如果这不是问题,也许你不看宽的瓷砖?这个模板适合宽广的平铺,所以方形平铺不会被这个更新。我建议使用NotificationsExtensions库。它最初用于Windows应用商店应用,但我认为它也适用于WP。 (我已经使用了它,但只是为了测试,不是真实的,所以可能会有问题。)它允许您轻松地指定宽方形和方形瓷砖的模板和参数。

最后,要获得宽广的图块,您必须手动编辑Package.appxmanifest文件。您必须将Wide310x150Logo属性添加到DefaultTile元素。

这就是我能想到的。希望能帮助到你。

相关问题