Google Glass is becoming an increasingly popular and recognizable device. Google is continually expanding the Explorer's Program—basically, beta testers for Google Glass—and recently even had an open enrollment. (Usually developers must be invited into the program.) As more people begin to use Google Glass, we'll see more opportunities to create never-before-seen apps to fill a new market or use-case. There are two ways to create apps (called Glassware) for Google Glass: using the Google Development Kit (GDK) or the Mirror Application Programming Interface (API). This article will focus primarily on the latter.
Why You Should Know About the Mirror API
My book Web Designer's Guide to Google Glass focuses on how to develop websites that look good on Google Glass, as well as other wearables. A major part of the book covers the Mirror API in depth, even showing how to build a simple application. You may wonder, "What's the point of covering an API when doing web design?" As it turns out, the Mirror API is very web-centric with regard to architecture. You can paginate notifications using the <article> element, you can use CSS and HTML to create specific card layouts, and the designs these languages propose for cards can apply nicely to web design with Google Glass in mind. I believe that knowing the Mirror API can lead to creating better websites on Google Glass and overall.
What the Mirror API Is Not
Before we dig into the Mirror API, let's look briefly at what the GDK can do and when you should use it, as opposed to using the Mirror API. The GDK is an add-on for the Android Software Development Kit (SDK), which requires the developer to have some familiarity with Java and Android development. You create an app by using an integrated development environment such as Eclipse with the Android SDK + GDK, compile the app to an Android Application Package file (APK), and install that APK on Google Glass (see Figure 1).
Figure 1 The flow for the GDK. Build the app using Android, create the APK, and install it on Glass.
The biggest difference is that apps built with the GDK run directly on Google Glass, whereas the Mirror API essentially runs as a web service. This design allows GDK-built apps to access low-level hardware, such as the camera or microphone. Google provides some great examples at the Glass Developers documentation site. By contrast, the Mirror API runs on a server rather than on the device, and it allows you to interact with the cards and Timeline only.
Google Glass Terminology and the Mirror API
The Google Glass interface is made up of cards that appear in some time-based sort order. The Clock card in the center is your home screen, information that you've seen or events that have happened appear to the right, and upcoming information is shown at left (see Figure 2).
Figure 2 How the Timeline works: upcoming stuff to the left of the time card, previous info to the right.
An API is software that allows you to interact with other software or hardware. For example, suppose a service lists video games on its website and you want to be able to access those games. Instead of gaining direct access to the service's database and source code, you can use the service's API, which will allow you to make calls to the service in order to achieve the same goal.
With the Mirror API, you can modify the Google Glass Timeline, using technologies you already know. Since Google Glass doesn't use native code, only API calls, you can code in whatever language you prefer, including Java, Python, Ruby, or PHP (which is what I use in my book's example). With most APIs, you write in a way that pulls data into your apps, but the Mirror API does almost the opposite; you write your app, and Google Glass reaches into the app and pull out its data.
Five Sections of Interactions
Up to this point, I've used Timeline as a blanket term for the entire Google Glass interface. But the Timeline is actually a single component of the whole set of Mirror API interactions:
- Timeline. Insert cards, add images and videos, bundle multiple cards, and access Timeline items.
- Menu Items. Make your cards interactive, using either built-in functionality or your own custom functionality.
- Subscriptions. Allows the developer to get notifications when a user performs specific actions such as sharing or updating location, or even voice detection. The developer can then respond to these user actions.
- Location. Access the last known location, subscribe to location updates, and display maps with this feature.
- Contacts. Perhaps the most complex aspect of the Mirror API, contacts are essentially broken up into two categories: People and Glassware. Contacts allows the user to share your cards with either category; for example, if the user selects the Share menu item, you would use contacts to make sure that your Glassware is available from that menu. Contacts also allow you to insert your own voice commands.
Ways of Using the Mirror API
Unfortunately, this article doesn't have space to run through an example (we'll leave that to Web Designer's Guide to Google Glass), but we can quickly review some possible uses for the Mirror API.
In the book, we build a "quote of the day" app that will push a random quote and photo to Google Glass. Imagine that we have another service that pulls the top tweet for a specific hashtag on Twitter every hour. We could use the Mirror API to push that tweet to the user. Apps have already been written to do something similar for headlines, sports scores, and more.
Since you can get the user's location by using the Mirror API, you could also do something like push "distance traveled" to the user's Timeline or even to the server that's running the API. This application could be useful for freelancers, for example; for tax purposes, they need to track the miles they travel
This article has barely scratched the surface of the Mirror API and what it can do. You can check out the examples in Web Designer's Guide to Google Glass and plenty more at the Google Doc developers site. Using the Mirror API, we can add interactive cards to Timelines, access the user's location, and even add voice commands to create powerful, lightweight, and familiar apps for Google Glass.