Google Glass – Making your first Glassware

Making and deploying your first Glassware

What are we going to do?

We will make Hello World Glassware to demonstrate how to make and deploy your first Glassware to the Google Glass.
Before you start you need to make sure your computer recognizes your Google Glass by following the steps of this article.
This Glassware is an example of an immersion. An immersion gives the developer the possibility to render the view. It replaces the timeline by an application.

Step 1 – Creating an Android Application Project

In Eclipse go to “File > New > Android Application Project” and choose an application name. For this project we will use HelloGlassware. We won’t change the Project Name or Package Name. Now choose API 19: Android 4.4 (KitKat) as Minimum Required SDK and Target SDK. Choose the Glass Development Kit Preview (Google Inc.) (API 19) to compile with and choose None as theme. This should look like the following image.

New Android Application

New Android Application

Press next, uncheck “Create Activity” and press next again twice. And press finish. Now we have made an empty project.

Step 2 – Create an immersion

In the src folder make a package called “com.example.helloglassware”. Create an Android Activity in this package and leave everything as it is. This will generate an “activity_main.xml” in the layout folder (we won’t use this for this example) and a Class called MainActivity that extends from Activity.
Because we want to be able to start this glassware by a voice command as well we will add some xml to the “AndroidManifest.xml”. Don’t forget to add the user-permission or it won’t work at all!
You can add this code sample under the uses-sdk tag.

AndroidManifest.xml

AndroidManifest.xml

This will give an error because there is no folder called “xml” and no file called “voice_trigger.xml” so lets make this!
In “res” make a folder called “xml” and add an xml file called “voice_trigger.xml”.
In this file add the following xml:

<trigger keyword="@string/app_name" />

The keyword “@string/app_name” refers to the “strings.xml” file where the app_name is “Glassware”. By saying this you will start the MainActivity. Don’t forget to change this in the strings.xml. (Recognition of voice doesn’t work well on longer names…)

Step 3 – Use the CardBuilder to create a view

In MainActivity we will change the onCreate implementation to:

onCreate implementation

onCreate implementation

This will make a new view with the layout Menu (you can choose other layouts if you like) you will set the text to “Hello World” and you will set the footnote to “By M&M” then you will use the view to set the content on the screen.
The onCreate method will be called when the activity is started. (For example the chosen voice command.)

Step 4 – Run the glassware!

Right click on your project and select run as > Android Application. It will ask on what device you want to run it. Select the Google Glass. Now you will be able to open the Hello Glassware application by using voice command and using the touchpad.

Leave a comment