While web apps work OK on Google Glass, if you want to make an app which looks great, is easy to use and can take advantage of Google Glass, you will need to make a native app.

Fortunately, it turns out that it is not that tough to do.



Write your app as usual in AppStudio. Choose the Google Glass form size and layout the forms. Drag and drop the using the regular controls (widgets) (don’t use anything that needs a keyboard!), set up titles and labels, etc. Programming can be in JavaScript or BASIC.

(if you haven’t encountered AppStudio before, here’s how to do HelloWorld.)

To turn your project into a native app, use PhoneGap CLI with the Cordova Glass plugin. You will need to follow the instructions here to set up the PhoneGap CLI environment on your system and to get your project ready.

To use Google Glass specific features, a plugin is needed. Cordova Glass is a PhoneGap plugin which makes it possible to receive all special Glass events from its touchpad. From the command line, enter this:

cordova plugin add https://github.com/aphex/cordova-glass

Events

Now, add support for gestures into your app. Here is what the code looks like to exit the app on a swipe down:

document.addEventListener("swipedown",onSwipeDown) Sub onSwipeDown() navigator.app.exitApp() End Sub

Here is the same code in JavaScript:

document.addEventListener("swipedown",onSwipeDown); function onSwipeDown() { navigator.app.exitApp(); }

You can react to the following events:

tap

longpress

swipeup

swipedown

swipeleft

swiperight

twotap

twolongpress

twoswipeup

twoswipedown

twoswipeleft

twoswiperight

threetap

threelongpress

scroll (returns data)

twofingerscroll (returns data)

fingercountchanged (returns data)

Tap is of course useful – it’s often used to drill down deeper into the app. Swipe Right and Swipe Left can be used to slide through the pages of your app.

Voice Control

The plugin also gives you the opportunity to set a couple of voice control options.

The Voice Prompt is what shows up on Glass’s menu after you say “OK, Glass”. You can start your app by saying the Voice Prompt when the menu shows.

The Voice Trigger is an additional voice command you can pass to your app. Set the prompt string (“What is your name?”) and it will be converted to text and passed to your app.

You can get more detail on this in the Google Glass TechNote.

Testing your App

Connect Glass to your system via the USB cable with debugging on. Choose “Build Native App with PhoneGap CLI” from the Run menu. Your app will compile, install and run on your Glass. You can use the Chrome Debugger.

Sample