Saturday, November 20, 2010

Windows Phone 7 Quick Tip #20 - Use ShellTileSchedule to easily update your Live Tiles

Live tiles are an important and key feature of Windows Phone 7.  You can create personalized Live Tiles using the notification services.  Although this isn’t terribly difficult it does require a bit of programming and at a minimum a simple server side service and some sort of persistence to track subscriptions on the server.

A simple option to update your Live Tiles is to use ShellTileSchedule to refresh your applications Live Tile.  This can be done in just a few lines of code:

var mySchedule = new ShellTileSchedule
{
    Interval = UpdateInterval.EveryHour,
    Recurrence = UpdateRecurrence.Interval,
    RemoteImageUri = new Uri(@
http://www.mysite.com/background.png,
                                       UriKind.Absolute)
};
mySchedule.Start();

Then all you need to do is setup some sort of process to update the live tile on the server, which in our case is at the fictional site http://www.mysite.com/background.png.  Your graphic should be the traditional 173x173 and must be smaller than 80kb.  Also if downloading the image takes more than fifteen seconds the operation will be aborted.  Finally if the operation fails more than three times, SchellTileSchedule will stop checking, until SchellTileSchedule.Start() is called again.

Please don’t stop reading yet

If you use ShellTileSchedule, you MUST add the following to your WMAppManifest.xml file.


<Capability Name="ID_CAP_PUSH_NOTIFICATION"/>



Even though this technically isn’t a Push Notification, you will get an InvalidOperationException when you call mySchedule.Start() without adding this capability.


Keep Reading!



UPDATED: 11/28/2010



Last week I submitted an application that used the above technique.  Even though it didn’t use any sort of “push-notifications” per-se I did have to add the ability to enable/disable and let the user opt out of doing this update via my applications user interface to get my application certified.




-twb


No comments:

Post a Comment