Dec 24, 2013

Hello World Immersion - Developing for Google Glass #2

This article describes how to create a simple hello world application for Google Glass using the Glass Development Kit (GDK). As described in the previous article you have two options how your Glassware should show up on the device: As a live card that is part of the timeline or as an immersion that is displayed outside of the context of the timeline. This article focuses on how to write an immersion.

What is an immersion?
An immersion is basically an Android activity. The name immersion implies that it is not part of the normal Glass timeline. Instead it takes full control of the device - except for the back gesture (Swipe down). To go back to the timeline you need to leave the immersion.

Once started an immersion takes full control of the screen.

Project setup
Create a normal Android project with the following settings:

  • Set minSdkVersion and targetSdkVersion to 15 (Android 4.0.3)
  • Set compileSdkVersion to "Google Inc.:Glass Development Kit Sneak Peek:15"
  • Do not assign a theme to your application or derive your own theme from Theme.DeviceDefault

Creating the immersion
Let's create a simple activity. The Card class helps us to create a layout that looks like a timeline card.

HelloWorldActivity.java

Launching the Glassware - Voice commands
After creating the activity we need a way to start our Glassware. A common way to launch Glassware is to use a voice trigger. Let's add a simple voice trigger to start our hello world activity.

First we need to declare a string resource for our voice command.

strings.xml

The next step is to create an XML resource file for the voice trigger using the previously created string value.

voice_trigger.xml

Now we can add an intent filter for the VOICE_TRIGGER action to our activity. A meta-data tag links it to the XML file we wrote above.

AndroidManifest.xml

The developer guide requires you to add an icon for the touch menu to the activity (white in color on transparent background, 50x50 pixels). The Glass Asset Studio is a helpful tool to generate these icons.


The final Glassware
Now we can start our Glassware by saying "ok glass, show hello world":


Another option to start our Glassware is to use the touch menu and scroll to the "show hello world" command:


The source code for this Hello World Glassware is available on GitHub.