Skip to main content
1-Visitor
July 26, 2016
Question

Set avatar for ThingTemplate in custom extension?

  • July 26, 2016
  • 14 replies
  • 5032 views

Hi,

I want to set the avatar for a ThingTemplate, and all implementing Things, in my custom extension. There's not much on this in the Extension Development Guide (v4).

Currently, I'm attempting to use SetAvatar in the initializeThing() method of my extensions ThingTemplate.

@Override

public void initializeThing() throws Exception {

     super.initializeThing();

    InputStream stream = this.getClass().getClassLoader().getResourceAsStream(resourceName);

   if (stream == null) {

       throw new Exception("Cannot get resource \"" + resourceName + "\" from Jar file.");

   }

    byte[] content = Base64.encode(IOUtils.toByteArray(stream));

   this.setAvatar(content);

}

resourceName is the name of a PNG image located in the root of my extension project directory.

Is their annotation or aspect I should be setting?

Thanks,

Shane

14 replies

5-Regular Member
July 26, 2016

Shane,

What happens when the code you cited above is exercised?

Meghan

sclifford1-VisitorAuthor
1-Visitor
July 27, 2016

Meghan,

Thanks for getting back to me.
Nothing happens; no exception is thrown and the code after (which retrieves values from the configuration table) runs as expected. However, the avatar image is not set for the ThingTemplate or initialised Thing in the Composer.
I will try open up a debug port on my local Tomcat instance and step through the code from my Eclipse IDE.
Shane
1-Visitor
July 27, 2016

I don't know if that's the case, but sometimes you can have Cache Problems with ThingTemplate's Avatar, did you tried to refresh Composer browser tab with shift key pressed?

1-Visitor
July 27, 2016

If you look at your code, Meghan it's using .SetAvatar and Shane it's using .setAvatar, that lower case can be the clue...

sclifford1-VisitorAuthor
1-Visitor
July 27, 2016

That was a typo ... my bad. In the actual code it is .SetAvatar

1-Visitor
July 27, 2016

Hi Shane,

Just download the extensions which does it, and look onto the code how they do it

Carles.