How to update Live Tile in Universal Windows apps?


Few days ago in a blog post we learnt “How to create Schedule Task in Universal Windows apps?”. Today in this blog post we will discuss how to update live tile in an universal Windows apps. Though you don’t need to create schedule task to update live tiles but you can surely use it anytime.

 

Read more to learn how easy it is to configure your app to support live tile updates and integration of it with schedule task.

 

Users of your apps have always the demand to see a live tile notification in their screen, which enables them to see the details or most important stuffs without opening the main app. If anytime you are planning to build an app with live tile notifications, this post will help you to set it up quickly.

 

Here is a code snippet for you to get started, which accepts a string parameter which will be placed in your live tile:

 

private static void UpdateTile(string infoString) {         // create the instance of Tile Updater, which enables you to change the appearance of the calling app's tile         var updater = TileUpdateManager.CreateTileUpdaterForApplication();         // enables the tile to queue up to five notifications         updater.EnableNotificationQueue(true);         updater.Clear();

        // get the XML content of one of the predefined tile templates, so that, you can customize it         XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150Text04);         tileXml.GetElementsByTagName("text")[0].InnerText = infoString;

        // Create a new tile notification.         updater.Update(new TileNotification(tileXml));

}

 

First of all, you need to create an instance of the Tile Updater. It will enable you to change the appearance of the calling app’s tile. You can get the instance of it by calling the static method TileUpdateManager.CreateTileUpdaterForApplication().

 

On top of the tile updater instance, call EnableNotificationQueue method passing “true” to it as a boolean parameter. This will enable the tile to queue up to five notifications. Now call the updater.Clear() method before setting up the text into it.

 

Next step is to get the XML content of one of the predefined tile templates, so that, you can customize it further. Put the XML template in XmlDocument object. There are a no. of tile templates available, which you can find in the Microsoft MSDN page for “Tile Template Catalog (Windows Runtime apps)”. Choose your appropriate tile template from the list and pass it to the GetTemplateContent method (as shown above).

 

Next is to set the string content to the live tile template. As we are using TileWide310x150Text04 tile template type here, we are setting the “text” element found at the zero’th position.

 

Finally call the updater.Update(new TileNotification(tileXml)) method passing the xml template as tile notification.

 

In case, you want to integrate live tile update in your Windows or Windows Phone universal app/game, read my previous post “How to create Schedule Task in Universal Windows apps?”. This will help you to create the scheduler task step-by-step. Once you have the background task ready, call the above UpdateTile method from the Run method of the background task. Make sure to add the Background Tasks declaration in to your manifest and configured the project properly.

 

I hope the post will help you to easily configure your apps/games to have a live tile notification system with a background schedule task. In case you are facing any difficulties, drop a line below and I will try to response back as soon as possible.

 

Connect with me on Twitter, Facebook and Google+ to get the updates that I share over those social networking sites. Did you subscribe to my blog’s RSS feed and/or email newsletter? If not, take a moment to subscribe to it to get the immediate article notifications in your inbox.

 


If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

9 comments

  1. Hi Kunal , Very helpful post along with code snippet :)

    ReplyDelete
  2. The blog post was helpful for using the templates, but that isn't interesting.

    If you could write as simple of a post about using Direct2D, or other method, to create CUSTOM live tile images for Universal Apps you would be the champion for us all!

    ReplyDelete
    Replies
    1. There has been one guy who wrote an API for that https://code.msdn.microsoft.com/windowsapps/High-Performance-tile-5d4d8e02 but basically don't do it. Live tiles aren't meant to be useful i guess...

      Delete
  3. Hi Kunal,

    could you add a section about getting images from the web to be shown on the tile? I'm really frustrated that this doesn't work for me and any help would be appreciated!

    ReplyDelete
    Replies
    1. Sure, I will probably write a blog post on this very soon.

      Delete
  4. I put this UpdateTile method in my app and called it as the MainPage.xaml.cs file ran. Nothing is shown on the tile when I go back to the main screen.

    ReplyDelete
  5. Hi Kuna,
    Thank you for great post. Could you help with xlm template "PeekImageAndText01" for example?
    I can't figure out how am I supposed to switch between image and text?

    ReplyDelete
  6. Hi, Kunal! First I want to say thanks for the post. very detailed and to the point.

    I have a quick question though. Im a C# dev and recently my company has the need for a RSS news feed with a live tile update (windows 10 only). Im kinda new to the universal apps stuff and was hoping you can help point me in the right direction.

    Thanks again

    ReplyDelete

 
© 2008-2016 Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top