javagoogle-glassgoogle-mirror-api

Can't display image on localhost in a static card


I am trying to create a card that displays an image on localhost for Google Glass. I'm building from the java-starter project for the Mirror API. In fact, I am trying to use one of the images that came with the starter app.

Here is the html of the card I am sending:

<article>
   <figure>
      <img src="http://localhost:8080/static/images/chipotle-tube-640x360.jpg">
   </figure>
   <section>
       <p class="text-small yellow">ABC</p>
       <p class="text-small">XYZ</p>
   </section>
</article>

I've tested this in the mirror-api playground https://developers.google.com/glass/tools-downloads/playground and it seems to display fine on there, but not on the glass device. Any ideas why?


Solution

  • The way you are sending the card, it has a reference to the URL of the image instead of the image as an attachment. To resolve this image, Glass goes out to that URL and tries to get the image.

    Since the server itself is not running on Glass, it can't resolve the URL and can't get the image. This is the same situation if you were running your web server on one machine, your browser on another, and using "localhost" for the hostname.

    You have a couple of solutions to this:

    1. You can use a globally available hostname or IP address. ("localhost" isn't going to be globally available, and IP addresses that start with "192.168" and some others won't be either.)
    2. Attach the image to the card and use the special URL attachment:0 to reference the first attachment.