I am currently working on a feed reader app in HTML5/JavaScript and I have a problem with live tiles. I have a live tile that is updating periodically by querying a web service that is returning the latest 3 articles from a blog. The live tile works as expected, but I want to create a badge notification that will display the unread articles.
The way I have thought to do this is to see if a tile updates and then increment the number from the badge notification. When the user launches the app, the badge will be cleared.
I use the following lines of code:
var notifications = Windows.UI.Notifications;
var polledUri = new Windows.Foundation.Uri("http://my_url/feed.php");
var recurrence = notifications.PeriodicUpdateRecurrence.halfHour;
var tileUpdater = notifications.TileUpdateManager.createTileUpdaterForApplication()
tileUpdater.startPeriodicUpdate(polledUri, recurrence);
This creates the live tile that updates every half an hour. My problem is: I want to create a badge update every time the PeriodicUpdate takes place. I use the following code:
var badgeType = notifications.BadgeTemplateType.badgeNumber;
var badgeXml = notifications.BadgeUpdateManager.getTemplateContent(badgeType);
var badgeAttributes = badgeXml.getElementsByTagName("badge");
var tileUpdater = notifications.TileUpdateManager.createTileUpdaterForApplication()
tileUpdater.startPeriodicUpdate(polledUri, recurrence);
// this is where my problem is
// if (tileUpdater.update() == true) -> This line is not correct: how can I catch the update event?
//badgeAttributes[0].setAttribute("value", currentValue + 1);
var badgeNotification = new notifications.BadgeNotification(badgeXml);
notifications.BadgeUpdateManager.createBadgeUpdaterForApplication().update(badgeNotification);
I want to catch the update event of that tileUpdater.startPeriodicUpdate function and increment the value of the badge. How can I do that? I have searched everywhere and I could not find an answer.
I appreciate your help.
Julian Atanasoae