FMX.Mobile.GoogleGlass Sample (Object Pascal)
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 | Appmethod 1.16 | Samples and then navigate to:
- CPP\Mobile Samples\Google Glass
- Object Pascal\Mobile Samples\Google Glass\GlassLevel
- Subversion Repository:
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
- Navigate to Start | Programs | Appmethod 1.16 | Samples, go to Object Pascal\Mobile Samples\Google Glass, and open GlassLevel.dproj.
- Build GlassLevel.dproj.
- Run the application by selecting the Run > Run menu from within the IDE, or by pressing F9.
- 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.
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="com.google.android.glass.permission.DEVELOPMENT" />
Inside the <intent-filter> element
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
Inside the <activity> element
<meta-data android:name="com.google.android.glass.VoiceTrigger" 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.
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.