Skip to main content
1-Visitor
Jul 26, 2016 4:17 PM UTC
Question

Set avatar for ThingTemplate in custom extension?

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
Jul 26, 2016 4:31 PM UTC

Shane,

What happens when the code you cited above is exercised?

Meghan

Translate
sclifford1-VisitorAuthor
1-Visitor
Jul 27, 2016 7:12 AM UTC

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
Translate
1-Visitor
Jul 27, 2016 7:25 AM UTC

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?

Translate
1-Visitor
Jul 27, 2016 1:00 PM UTC

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

Translate
sclifford1-VisitorAuthor
1-Visitor
Jul 27, 2016 1:28 PM UTC

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

Translate
1-Visitor
Jul 27, 2016 1:43 PM UTC

Hi Shane,

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

Carles.

Translate