Windows 8.1 Preview: Declarative Polling of Tiles

One of the easiest ways in which you can get a tile (or a badge) to be ‘Live’ on Windows 8 is to set up a URL which delivers tile content. This is known as a “periodic notification” and the essence of it is;

  1. Web service which returns dynamically generated XML (possibly varying on culture information or even some unique identifier for the client app or its user).
  2. Simple bit of code that needs to be run in the client side app to tell the system which URL to poll for tile/badge content and how frequently to poll it.

A small, but useful, change on Windows 8.1 is that it’s possible to get the basics of this up and running without even writing that piece of code – it can be done declaratively.

For demo purposes I set up a basic piece of XML data on my website a long time ago. It’s hanging off https://mtaulty.com/downloads/tile.xml and the content of that URL looks like this;

<?xml version="1.0"?>

-<tile>


-<visual lang="en-US">


-<binding template="TileWideImageAndText01">

<image src="https://mtaulty.com/downloads/mslogo.png" id="1"/>

<text id="1">from web URL</text>

</binding>

</visual>

</tile>

Naturally, it’s perhaps more likely that the content of a tile would be served dynamically rather than just statically always returning the same content but that’s not too relevant for the client-side of things.

On Windows 8.0, I’d have to hope that when the user installed my app, they would run it causing to execute a piece of code that I might run just once on the first run of the app;

      var key = "RunOnce";

      if (!ApplicationData.Current.LocalSettings.Values.ContainsKey(key))
      {
        ApplicationData.Current.LocalSettings.Values[key] = true;

        var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
        tileUpdater.StartPeriodicUpdate(
          new Uri("https://mtaulty.com/downloads/tile.xml", UriKind.Absolute), 
          PeriodicUpdateRecurrence.HalfHour);

      }

Of course, there’s the small problem of how to have a live tile if the user doesn’t run the app immediately or perhaps for a little while which is where Windows 8.1 steps in and makes this something that you can set up declaratively. That is – if I take the above code out of my app I can edit the app’s manifest in Visual Studio;

image

and I’m done. As soon as the app is installed my tile is live containing (e.g.) today’s news headlines or the top 3 titles of mails in my inbox and, from the user’s perspective, that’s pretty cool because they know that they didn’t even run your app yet Smile

Note: as the piece of UI from Visual Studio says – it’s possible to embed {language} and {region} tokens into that URL if you wanted to customise the tile data sent back for those settings. I guess that if you need to go beyond that then you can maybe use this mechanism to get going and once your app code runs, replace the URL being used with a more specialised one based on (e.g.) a user id or similar.