locked
WinRT live tile badge update RRS feed

  • Question

  • 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
    Tuesday, January 15, 2013 8:05 PM

Answers

All replies

  • Hi,

    Actually, you can use  Windows Azure Mobile Services to send title in your Windows Store app.

    More details, please refer to: http://code.msdn.microsoft.com/windowsapps/site/search?f%5B0%5D.Type=SearchText&f%5B0%5D.Value=live%20tile&f%5B1%5D.Type=ProgrammingLanguage&f%5B1%5D.Value=JavaScript&f%5B1%5D.Text=JavaScript .


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 16, 2013 8:51 AM
  • Can't it be done without Azure Mobile Services? (I don't have a permanent subscription)
    Wednesday, January 16, 2013 4:19 PM
  • Hi,

    A tile notification can originate either from a local API call or from the cloud. A badge is a number or glyph that is displayed in the lower right corner of a tile (or the lower left corner if the UI uses a right-to-left language) to indicate an app's status in some way. The badge is an overlay on the tile, not a part of the tile itself. The badge is manipulated through its own APIs and schema and is updated through its own notifications. 

    #Quickstart: Sending a badge update (Windows Store apps using JavaScript and HTML) (Windows)

    http://msdn.microsoft.com/en-us/library/windows/apps/hh700418.aspx

    #Tile and tile notification overview (Windows Store apps) (Windows)

    http://msdn.microsoft.com/en-us/library/windows/apps/hh779724.aspx

    Any more question, please feel free to reply.


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, January 17, 2013 3:16 AM
  • Hi jatanasoae,

    I don't find a function you can use in "startPeriodicUpdate". But I find badge has the same function as follow:

    Notifications.BadgeUpdateManager.createBadgeUpdaterForApplication().startPeriodicUpdate(polledUri, recurrence);

    So you may do that as follow:

    Notifications.TileUpdateManager.createTileUpdaterForApplication().startPeriodicUpdate(polledUri, recurrence);
    Notifications.BadgeUpdateManager.createBadgeUpdaterForApplication().startPeriodicUpdate(polledUri, recurrence);
    

    #Quickstart: Setting up periodic notifications (Windows Store apps using JavaScript and HTML) (Windows)

    http://msdn.microsoft.com/en-us/library/windows/apps/Hh761476(v=win.10).aspx

    #BadgeUpdateManager.CreateBadgeUpdaterForApplication() | createBadgeUpdaterForApplication() method (Windows)

    http://msdn.microsoft.com/en-us/library/windows/apps/br208533.aspx


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, January 17, 2013 6:23 AM
  • If I use this method, I would have to create unique IDs for all the clients on the web service and increment the unread articles value for each client and send it with a badge update. This may be a problem if I have a lot of users (the file with the IDs would be very big)

    Can you suggest another method?

    Julian

    Thursday, January 17, 2013 8:20 AM
  • Hi jatanasoae,

    Then you can use a background timer to provide periodic tile or badge updates.

    #How to run a background task on a timer (Windows Store apps using JavaScript and HTML) (Windows)

    http://msdn.microsoft.com/en-us/library/windows/apps/jj160504.aspx


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, January 18, 2013 5:59 AM
  • Actually there are 2 solutions to this problem:

    1) I can create a periodic notification for a badge update and store GUIDs for each client on a web service. This solution would work for apps that are not heavily used, otherwise the file that stores the unique IDs on the server would get too big and the web service would have to increment a lot of values for each client. More than that, if a user uninstalls the app, his specific GUID still remains stored on the server and that value would be incremented with no use, and then I would have to make a cleanup if that value isn't called for a period of time or something like that.

    2) I can create a background task with a timer and call the tile and badge update functions once every half an hour or so. This would be a better solution, because the server doesn't store any values, it doesn't have to spend compute power to increment those values and all the work is done on the client, which can decide if the app is allowed to run in the background and get updates.

    So I guess I'm gonna go with the second solution. Thank you all for your help.

    Julian

    Friday, January 18, 2013 2:18 PM