locked
Periodic Live Tile and Not Sure how URL works

    Question

  • Hi ,

    I am not sure how to use the URL. I could not find any example that for periodic Live Tile.

    Below is the code I got from somehere. But I don't really know what is the URL thing.

    using Windows.UI.Notifications;

    Uri polledUri = new Uri(http://www.123.com/delivery/address.aspx);

    PeriodicUpdateRecurrence recurrence = PeriodicUpdateRecurrence.Hour;

    TileUpdateManager.CreateTileUpdaterForApplication().StartPeriodicUpdate(polledUri, recurrence);

    Can some1 show me how to write a simple code that return xml in address.aspx ?

    1) http://www.123.com/delivery/address.aspx

    How to return XML string in address.aspx when this URl is used?

    <tile>
      <visual version="2">
        <binding template="TileSquare150x150Block" fallback="TileSquareBlock">
          <text id="1">Text Field 1 (block text)</text>
          <text id="2">Text Field 2</text>
        </binding> 
      </visual>
    </tile>

    2) What are the Settings need to be done in the aspx page?

    Thanks

    Wednesday, March 11, 2015 2:44 PM

Answers

  • Hi Machine7,

    I think we have to use template instead of using XML directly, see this: TileTemplateType enumeration

    After getting data from remote, we can fill in the tile template with text, see this: Quickstart: Sending a tile update, I paste some code snippet here for your reference.

    XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150ImageAndText01);
    // you can get Text from your XML get from URI.
    XmlNodeList tileTextAttributes = tileXml.GetElementsByTagName("text");
    tileTextAttributes[0].InnerText = "Hello World! My very own tile notification";
    
    XmlNodeList tileImageAttributes = tileXml.GetElementsByTagName("image");
    ((XmlElement)tileImageAttributes[0]).SetAttribute("src", "ms-appx:///assets/redWide.png");
    ((XmlElement)tileImageAttributes[0]).SetAttribute("alt", "red graphic");
    
    XmlDocument squareTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Text04);
    XmlNodeList squareTileTextAttributes = squareTileXml.GetElementsByTagName("text");
    squareTileTextAttributes[0].AppendChild(squareTileXml.CreateTextNode("Hello World! My very own tile notification"));
    IXmlNode node = tileXml.ImportNode(squareTileXml.GetElementsByTagName("binding").Item(0), true);
    tileXml.GetElementsByTagName("visual").Item(0).AppendChild(node);
    
    TileNotification tileNotification = new TileNotification(tileXml);
    
    tileNotification.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(10);
    
    TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, March 25, 2015 10:09 AM
    Moderator

All replies

  • It doesn't have to be an ASPX page.  Put a file on the server - tiledata.xml and just write it. Then point the URL to it. You can update that text file when you want to app tile to change. ASPX is just a server side asp page. Response.Write("<XML DATA HERE>"); will output the xml. You don't need any fancy formatting, just output plain text.

    Jason Short

    Wednesday, March 11, 2015 8:17 PM
  • Hi,

    Some questions to help me to understand better.

    a) Where to place the this code for the Win8 App to start the Live Tile?

    in the MainPage or in App.xaml.cs?

    Uri polledUri = new Uri(http://www.123.com/delivery/address.aspx);

    PeriodicUpdateRecurrence recurrence = PeriodicUpdateRecurrence.Hour;

    TileUpdateManager.CreateTileUpdaterForApplication().StartPeriodicUpdate(polledUri, recurrence);

    b) What happen to the Live Tile When the App is closed. What it will show the old data?

    c) On server side Asp.net :

    protected void Page_Load(object sender, EventArgs e)
    {
       String xml = "<tile>
       <visual version="2">
         <binding template="TileSquare150x150Block" fallback="TileSquareBlock">
           <text id="1">Text1</text>
           <text id="2">Text2</text>
         </binding> 
       </visual>
     </tile>";

       Response.Clear();
       Response.ContentType = "text/xml";
       Response.Write(xml);


    }

     c1. Do I have to use ContentType ?

    c2.  How to handle the double quote  like "2" in writing the XML .

    c2. Can I do don't put anything if there is no data like below

           <text id="1"></text>

           <text id="2"></text>

    Thanks

    Thursday, March 12, 2015 12:48 PM
  • Hi Machine7,

    a) Where to place the this code for the Win8 App to start the Live Tile?

    -> It depends on you, you would like to initialize the Live Tile update while the app is starting you can put the code at app.xaml.cs, otherwise you could run the code at main page. It depends on different scenario, for example we have a weather app, we need user to configure their location to update the weather data. If you have code to identify the location, you can also initialize the Live Tile update on app.xaml.cs.

    b) What happen to the Live Tile When the App is closed. What it will show the old data?

    -> What do you mean the old data, basically Live Tile update is a kind of background task, Quickstart: Update a live tile from a background task, you may see some limitation of the background task for instance update frequency or data limitation, see this: Periodic notifications. If you update the latest data, then the new data will shown.

    c1. Do I have to use ContentType ?

    c2.  How to handle the double quote  like "2" in writing the XML .

    c2. Can I do don't put anything if there is no data like below

           <text id="1"></text>

           <text id="2"></text>

    I believe you can see more information for what you want from here: https://code.msdn.microsoft.com/windowsapps/app-tiles-and-badges-sample-5fc49148, to handle double quote we can ref to this: string, at sign or back slash is suggested.

    Basically all the Tile need to follow the Tile template The tile template catalog. if there is no content, I would suggest you select a more suitable Tile template.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 18, 2015 9:21 AM
    Moderator
  • Hi Jamles,

    Suppose using this URL ( not the real one)

    strURL ="http://www.123.com/ssyservice/ssoservice/edt1/getlessonplanupdateswin8/20000101010000"

    it return this ( When I test it on IE browser)

    <?xml version="1.0"?>
    <string xmlns="<tile><visual">http://schemas.microsoft.com/2003/10/Serialization/"><tile><visual version="2"><binding template="TileSquare150x150Block" fallback="TileSquareBlock"><text id="1">1</text><text id="2"> lessons updated</text></binding></visual></tile></string>

    in Main Page :

     public MainPage()
            {
                this.InitializeComponent();

                retrieveUpdate();

            }

    private void retrieveUpdate()
            {
              
      Uri polledUri = new Uri(strURL);


                PeriodicUpdateRecurrence recurrence = PeriodicUpdateRecurrence.HalfHour;

                TileUpdateManager.CreateTileUpdaterForApplication().StartPeriodicUpdate(polledUri, recurrence);
               
            }

    But nothing show up after halfHour.

    Do I miss anything ?

    Thanks


    • Edited by Machine7 Thursday, March 19, 2015 10:19 AM
    Thursday, March 19, 2015 10:18 AM
  • Do I have to wait half an hour to see the result?

    is that a way I can view is there is any return result immediately?

    Thursday, March 19, 2015 12:33 PM
  • hi

    Have not used this feature before. need help to solve this problem. 

    This is the live tile template I will be using:

    <tile>
       <visual version="2">
         <binding template="TileSquare150x150Block" fallback="TileSquareBlock">
           <text id="1">Text Field 1 (block text)</text>
           <text id="2">Text Field 2</text>
         </binding> 
       </visual>
     </tile>

    1) I need to retrieve data from server. I will get either Asp.net or PHP to return the XML Data.

    Do I get Aspnet or PHP to return XML Data as below:

    <?xml version="1.0" encoding="utf-8"?>    //<-- with this or without this?
    <tile>
       <visual version="2">
         <binding template="TileSquare150x150Block" fallback="TileSquareBlock">
           <text id="1">Test 1 (block text)</text>
           <text id="2">Test 2</text>
         </binding> 
       </visual>
     </tile>

    is this required as part of the XML data? : <?xml version="1.0" encoding="utf-8"?>   

    2) How to I get daily Update?

    Thanks

    Sunday, March 22, 2015 10:57 AM
  • Any1 can help? I need some help on this live tile.
    Monday, March 23, 2015 8:18 AM
  • Hi Machine7,

    I think we have to use template instead of using XML directly, see this: TileTemplateType enumeration

    After getting data from remote, we can fill in the tile template with text, see this: Quickstart: Sending a tile update, I paste some code snippet here for your reference.

    XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150ImageAndText01);
    // you can get Text from your XML get from URI.
    XmlNodeList tileTextAttributes = tileXml.GetElementsByTagName("text");
    tileTextAttributes[0].InnerText = "Hello World! My very own tile notification";
    
    XmlNodeList tileImageAttributes = tileXml.GetElementsByTagName("image");
    ((XmlElement)tileImageAttributes[0]).SetAttribute("src", "ms-appx:///assets/redWide.png");
    ((XmlElement)tileImageAttributes[0]).SetAttribute("alt", "red graphic");
    
    XmlDocument squareTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Text04);
    XmlNodeList squareTileTextAttributes = squareTileXml.GetElementsByTagName("text");
    squareTileTextAttributes[0].AppendChild(squareTileXml.CreateTextNode("Hello World! My very own tile notification"));
    IXmlNode node = tileXml.ImportNode(squareTileXml.GetElementsByTagName("binding").Item(0), true);
    tileXml.GetElementsByTagName("visual").Item(0).AppendChild(node);
    
    TileNotification tileNotification = new TileNotification(tileXml);
    
    tileNotification.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(10);
    
    TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, March 25, 2015 10:09 AM
    Moderator