FMX.GoogleGlass Sample

From RAD Studio Code Examples
Jump to: navigation, search

This is a sample project with Google Glass, although it will also run with similar functionality on most Android devices.


You can find the GoogleGlass sample project at:

  • Start | Programs | Embarcadero RAD Studio Alexandria | Samples and navigate to:
    • Object Pascal\Multi-Device Samples\Google Glass\GlassLevel
    • CPP\Multi-Device Samples\Google Glass
  • Subversion Repository:
    • You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.s


This application uses the Google Glass style, uses the WakeLock to keep an Android device awake, and launches the app with voice on Google Glass.

Move your head (while wearing Google Glass) to provide input to this app. As you tip your head from left to right, you see the line also tips. As your lean your head forward and backward, you see the line also moves up and down. The lower corners display the value of the lines' movement.

How to Use the Sample

  1. Navigate to the one of the locations given above, and open:
    • Delphi: GlassLevel.dproj
    • C++: GlassLevelCpp.cbproj
  2. Press F9 or choose Run > Run.
  3. Build GlassLevel.dproj.
  4. Run the application by selecting the Run > Run menu from within the IDE, or by pressing F9.
  5. Launch it again from Google Glass by going to the Home Screen and saying "OK Glass, Am I Level?" or selecting the "Am I Level" from the app list.

Voice Launch

The voice trigger is added in multiple steps. In the AndroidManifest.template.xml file the following lines were added:

A special permission is required to use a non standard voice trigger command. In the Manifest, right below the <%uses-permission%> line you need to add the following special permission:

<uses-permission android:name="" />

Inside the <intent-filter> element

<action android:name="" />

Inside the <activity> element

  android:resource="@xml/voice_trigger_start" />

The @xml/voice_trigger_start is a reference to the voice_trigger_start.xml file, which is also included in the project.

It is a standard XML file with the element:

<trigger keyword="Am I level?" />

Where "Am I level?" is the voice trigger keyword.

The voice_trigger_start.xml also requires deployment to the res\xml folder. This is specified under the Project > Deployment screen for the Android platform.

For more information on the Google Glass Voice Trigger, check out the GDK documentation.


File Contains


The JNI Interface for the PoweManager, WakeLock classes and a few helper methods to acquire a WakeLock.


Edited lines to add the voice trigger in order to launch an app with voice on Google Glass.


The project itself.


The main form and code to display the level.


Contains the voice trigger keyword to launch the app.


Further information about this sample.


  • To provide smooth animation of level movement, TFloatAnimation is used.
  • To obtain acceleration information for the movement of the level, TMotionSensor is used.
  • To enable and disable the wake lock at the right time, TPlatformServices.Current.SupportsPlatformService is used.
  • JPowerManager and JWakeLock keep the device awake (Androidapi.JNI.PowerManager.pas file).
  • To obtain WakeLock Uses Permission go to Project > Options menu from within the IDE, then to Uses Permissions.


See Also

Creating Applications for Google Glass