4

I've been trying to add a custom icon into a Filled Panel.

In the documentation there is some information on this in section 8.5 and the examples in the SDK's demonstrate that a developer can customise the Large and small icon of the tile. However there is no clear example of how to do this for a custom icon within the tile on a page.

Searching further, I found that there was a new Microsoft Band Tile Design Plugin for Visual Studio. This seems to demostrate what I wanted to do however when trying to use the code specified in the Code Generation section (Half way down the page), I failed to load a simple custom layout that I had created using the designer:

enter image description here

Here is the code that is linking the custom layout as described on the Tile Design Plugin Page:

try
            {
                // create a new Guid for the tile
                tileGuid = Guid.NewGuid();
                // create a new tile with a new Guid
                WriteableBitmap smallIconBitmap = new WriteableBitmap(24, 24);
                BandIcon smallIcon = smallIconBitmap.ToBandIcon();
                WriteableBitmap tileIconBitmap = new WriteableBitmap(48, 48);
                BandIcon tileIcon = tileIconBitmap.ToBandIcon();
                BandTile tile = new BandTile(tileGuid)
                {
                    // Name of the Tile
                    Name = "MyTile",
                    // Create the small and tile icons from writable bitmaps.
                    // Small icons are 24x24 pixels.
                    SmallIcon = smallIcon,
                    // Tile icons are 46x46 pixels for Microsoft Band 1, and 48x48 pixels
                    // for Microsoft Band 2.
                    TileIcon = tileIcon
                };
                var customtiledesign = new SentimentFeedbackLayout();
                tile.PageLayouts.Add(customtiledesign.Layout);
                await customtiledesign.LoadIconsAsync(tile);

                if (await bandClient.TileManager.AddTileAsync(tile))
                {
                    Debug.WriteLine("New tile added | GUID: " + tileGuid);
                }

                PageData pd = new PageData(tileGuid, 1, customtiledesign.Data.All);

                if (await bandClient.TileManager.SetPagesAsync(tileGuid, pd))
                {
                    Debug.WriteLine("Added pages");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

The error log is as follows:

Band Connected : MSFT Band 2 bb:bc
Version: 2.0.4215.0, Hardware: 26
Band - Removing all Tiles
Removed tile: MyTile
New tile added | GUID: 4803e0fe-2da2-4efb-9389-bde3a9289d30
Exception thrown: 'Microsoft.Band.BandOperationException' in mscorlib.ni.dll
Error Device status code: 0xA0CC006A received.

I couldn't find any details of the error online but I think its because I've used:

 PageData pd = new PageData(tileGuid, 1, customtiledesign.Data.All);

Instead of passing the customtiledesign.Data.All into the ...SetPagesAsync() method.

This was because there was no overloaded form of SetPageAsync that took PageElementData[] as an argument.

Stevenyc091
  • 195
  • 1
  • 2
  • 22
  • I'm having the same problem there doesn't seem to be clear documentation for this –  Mar 14 '16 at 04:03

2 Answers2

1

The reason why the icon is not visible on the tile layout is because of index 1 passed to the constructor here: PageData pd = new PageData(tileGuid, 1, customtiledesign.Data.All);. It should be 0.

I.e. your tile could have several layouts and your call was setting the data for the 2nd non-existing layout. For the only layout you added the index is 0.

When you succeed with this you will likely notice that your tile will have no good icons. This is because smallIconBitmap and tileIconBitmap need some good source before the call ToBandIcon. Samples provide the following code for loading icons.

    private async Task<BandIcon> LoadIcon(string uri)
    {
        StorageFile imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(uri));

        using (IRandomAccessStream fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
        {
            WriteableBitmap bitmap = new WriteableBitmap(1, 1);
            await bitmap.SetSourceAsync(fileStream);
            return bitmap.ToBandIcon();
        }
    }
  • I've tried loading two pngs as the tile icons. I don't they're the right size. Does this make a difference? I'm using this method to load them. I'm now getting: 0xA0D30003 received. –  Mar 14 '16 at 19:50
  • I'm no longer getting any error after updating the SDK, however although the page data is being loaded. The tile is still not showing icon on the page. –  Mar 17 '16 at 01:31
  • I've loaded the custom view with a text box to prove its working. I've also changed the icons to the correct sizes. However, I'm still not seeing the images that I've put into the design. –  Mar 18 '16 at 13:47
  • Could your icon be really big? The designer is a desktop application and it can show icons taking lots of memory. The band cannot. I would try first using the same code, the same design but refer to the smiley face from the TilesEvent sample. – AndrewGa MSFT Band SDK Mar 19 '16 at 00:52
  • If smiley face also does not work (i.e. you see it in designer, but not on the band) then probably customtiledesign.LoadIconsAsync generated to the designer refers to the resource which is not available at the location when you call that method. Theoretically that method should have raised an exception but I do not remember for sure. – AndrewGa MSFT Band SDK Mar 19 '16 at 00:58
  • If you prove that the LoadIcons call does not load the right resources then you can try adjusting the icon loading algorithm. There are properties: AdjustURIMethod and LoadIconMethod on that generated class SentimetFeedbackLayout. – AndrewGa MSFT Band SDK Mar 19 '16 at 01:00
  • I've tried several images, none of which work. I'm not quite sure what I would do to change these methods. The file seems to load properly (Debugger shows Icon Data populated) . I've also tried debugging the location of where the icons are being save. As I'm using xamarin, I tried using the [PCL Storage](https://github.com/dsplaisted/PCLStorage) to see what was in the assets folder and got an "Access Denied" error however I'm guessing this is because I'm trying to access it from another library? –  Mar 20 '16 at 00:16
  • Sorry to clarify, I'm using xamarin but the band code is in the UWP project –  Mar 20 '16 at 00:45
  • It looks like the only way to figure out what is wrong is to ask you to provide us the simplest "repro" solution. If you could upload it we would be able to look and suggest a fix. The right way for us to exchange information would be if you opened a topic here: http://answers.microsoft.com/en-us/band – AndrewGa MSFT Band SDK Mar 22 '16 at 18:04
  • Andrew, I've opened a [question](http://answers.microsoft.com/en-us/band/forum/msband2-band_tiles/microsoft-band-development-loading-icons/feb8f2d5-52f0-4656-b279-aa6947e0d341) with pastebins to the code included: –  Mar 28 '16 at 15:58
  • I am having trouble replying there :-( so I will reply here. Please look at "another answer" I am posting. – AndrewGa MSFT Band SDK Mar 30 '16 at 18:50
0

Please try calling LoadIconsAsync before the call to AddTileAsync (flip the lines shown in the code piece below). This is most likely the cause and I have just verified that. In our documentation for the designer there are 2 sample pieces of code. The first one is incorrect. It calls the way you have tried it in the version of the code posted to MSDN forum. The second example is correct. We will fix the documentation ASAP. Sorry about that.

The code piece presented in this particular question had it right but the code piece presented on MSDN question had the lines flipped. The AddTilesAsync was before LoadIconsAsync

1.if (await bandClient.TileManager.AddTileAsync(tile))

  1. {

  2. ...

  3. }

  4. await customLayout.LoadIconsAsync(tile);

Please also note that the usage of GetBandsAsync with argument True was recommended for Windows Phone 10 development in case of writing application services implementing IBackgroundTask objects. This is not the same as calling the async code from non-UI worker thread.

  • I've tried using the line before and after after. Both don't work unfortunately. –  Mar 31 '16 at 20:12
  • The only thing that i can imagine is the problem is that I'm using xamarin? I've put the controller into the UWP project folder. –  Mar 31 '16 at 20:19
  • We have not tried using the designer in the context of Xamarin. First we would like to get the idea about the demand. But you claim that the your Band SDK code in UWP project. So here is the link to a zip file with a UWP solution. The solution contains the designed layout and the code which consumes it. It works 100% on my devices. Please review it, compile and try to run it on your phone to see if it works. – AndrewGa MSFT Band SDK Mar 31 '16 at 21:56
  • Hit Enter too soon. If it works, please try to use your icons exactly in my project and see if it keeps working. If it stops showing the icon then we can discuss the format. If it does work with your icon then please try to see any difference between your project and mine. https://onedrive.live.com/redir?resid=4D46F45362D3AA5!56464&authkey=!AJ89-_KOJ2pmBCg&ithint=file%2czip – AndrewGa MSFT Band SDK Mar 31 '16 at 21:58
  • Solved it! :) For some reason I needed to generate a new GUID with Guid.NewGuid(); –  Apr 01 '16 at 23:51