1

I have a Windows Phone 8 app that I recently upgraded to 8.1 Silverlight. I'd like to use the new tile templates. Right now I have a ScheduledTaskAgent that uses ShellTile.

In order to use the new live tiles I changed the notification service to WNS in my WMAppManifest.xml. I removed the code to register the old background task and added this code instead:

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();
}

I created a Windows Phone 8.1 Windows Runtime Component called BackgroundTasks that contains a BackgroundTask called 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();
    }
}

I added a reference to this assembly in my Windows Phone project.

I also added a Background task declaration in my Package.appxmanifest that has BackgroundTasks.LiveTileBackgroundTask as an Entry point. I selected Timer and System event as supported task types.

When I run the app though, nothing happens. No live tile appears. I ran through the background task and everything goes well without any exceptions.

Leon Cullens
  • 12,276
  • 10
  • 51
  • 85
  • Hi, did you try just updating the tile in the foreground instead of in a background task? The reason that I asked is because I can't even get the tile to update in the foreground... – Justin XL May 11 '14 at 12:38
  • Hi Xin, I tried that and it didn't work either. – Leon Cullens May 12 '14 at 19:34
  • Please take a look at this one http://stackoverflow.com/questions/23589479/new-live-tiles-dont-work-in-windows-phone-silverlight-8-1-apps – Justin XL May 12 '14 at 22:33
  • @Xin thanks, I did set the notification service to WNS. Could you pastebin your manifest? – Leon Cullens May 13 '14 at 17:49

2 Answers2

3

You say "No live tile appears". The code you've posted does not create a live tile - it just updates one. You have to manually pin it - the primary tile cannot be pinned through code.

If that's not the problem, maybe you're not looking at the wide tile? This template is for a wide tile, so the square tile won't be updated by this. I'd suggest using the NotificationsExtensions library. It was originally for Windows Store apps, but I think it would work for WP as well. (I've used it, but just for a test, not for real, so there may be issues.) It allows you to easily specify the template and params for both wide and square tiles.

And finally, to have a wide tile, you have to manually edit the Package.appxmanifest file. You must add the Wide310x150Logo attribute to the DefaultTile element.

That's all I can think of. Hope it helps.

yasen
  • 3,580
  • 13
  • 25
1

Continuous background execution is not supported for Silverlight 8.1 apps

Windows Phone 8 apps can continue to run in the background after the user navigates away from the app under certain conditions. This feature is not available for Silverlight 8.1 apps. If you need this feature, you should continue to use a Windows Phone 8 app. For more information, see Running location-tracking apps in the background for Windows Phone 8.

Platform compatibility and breaking changes for Windows Phone Silverlight 8.1 apps

Windows Phone 8.1 Windows Runtime Component can only be used with Windows Phone 8.1 Runtime(Store) app

IceFog
  • 310
  • 2
  • 4
  • That's not what this is. It's not a "continuous background" task, it's just a normal background task that should be executed periodically. It does just that, but the tile doesn't get updated. If it wouldn't have been compatible it wouldn't have been able to compile. I should be able to use the new tile templates with WP8.1 Silverlight, but I don't think that they will work with the old ScheduledTaskAgent. – Leon Cullens May 10 '14 at 00:16
  • 1
    before criticize, it would be better read what is written in the link, see the next paragraph after that I put. You upgraded your old ScheduledTaskAgent to 8.1? And start with the fact that the idea of ​​using Windows Phone 8.1 Runtime Component for Windows Phone Silverlight 8.1 app it's ... and the same thing "I'd like to use the new tile templates" which only for the RT platform not for Silverlight – IceFog May 10 '14 at 04:25
  • "which only for the RT platform not for Silverlight" -> sorry but that's just not true. Multiple people within Microsoft explicitly confirmed that WP8.1 SL _can_ use the new tile templates. – Leon Cullens May 10 '14 at 11:18