-
Notifications
You must be signed in to change notification settings - Fork 22
How to write a Smart Glasses App in 30 minutes
This guide aims to take you from knowing nothing about the Smart Glasses Manager to having a fully-functioning smart glasses app in under 30 minutes.
- An android device
- (Optionally) a second android device for testing
- Experience with AndroidSDK, Android Studio, Java
- A pair of compatible smart glasses
If you haven't already, we highly suggest you skim our Smart Glasses Manager Wiki page for more information on how it works. However, if you just want a basic synopsis, the Smart Glasses Manager (SGM) handles the following things:
- Compatibility with a variety of smart glasses devices
- The Bluetooth connection between a phone and smart glasses
- The logic as to what information / apps are to be displayed on the connected smart glasses at any given moment
- Receiving data from outside sources and relaying said data to relevant apps
- Example: SGM receives audio and generates transcripts which can be accessed from other smart glasses apps
The SGMLib is an Android library that provides a simple interface for apps to interact with the SGM. It currently supports the following features:
-
Registering your app - and individual commands - with the SGM
-
Provides a service (
SmartGlassesAndroidService
) that can be started in the background by the SGM when required -
Subscribing to data streams from the SGM, such as audio transcripts
-
Requesting the SGM to display information on the connected smart glasses. The following screens are currently available:
- ReferenceCard: static screen with a title and body
- ScrollingText: dynamic screen with a title and body that can be appended to
We recommend you start by using our Example App as a base to work from.
Once you have it opened in Android Studio, note the two main Java files: MainActivity, and SgmLibDebugAppService.
In our example app, we use MainActivity to start and manage the state of SgmLibDebugAppService
, which extends SmartGlassesAndroidService
, which is a service the SGM can interface with.
Now, open SgmLibDebugAppService.java
. We start by calling super
in the constructor to initialize the service.
Next, we handle the rest of SGMLib's implementation in onCreate
. We start by creating an SGMLib
object, and passing it getApplicationContext()
:
sgmLib = new SGMLib(getApplicationContext());
Next, we define a command. Each command needs a name, UUID, list of trigger phrases, and a description:
UUID myUUID = new UUID.fromString("someUUID");
String[] triggerPhrases = {"hello world"};
SGMCommand helloWorldCommand = new SGMCommand("Debug One Shot", myUUID, triggerPhrases, "Hello world command desc");
We can also define a command that accepts arguments. This can be used, for example, in a search engine app, where the user needs to provide a search query after the initial command. Here's what that may look like:
ArrayList<String> exampleArgs = new ArrayList<String>(Arrays.asList("dog", "cat", "and other args"));
SGMCommand helloWorldWithArgsCommand = new SGMCommand("Debug With Args", myUUID, triggerPhrases, "Hello world command with args", true, "Debug args:", exampleArgs);
Next, we register the command with a callback that can be called by the SGM:
sgmLib.registerCommand(helloWorldCommand, this::helloWorldCallback);
Finally, we create our callback function helloWorldCallback(String args, long commandTime)
. Note that the SGMLib requires an argument parameter to be defined regardless of whether the command requires an argument from the user:
public void helloWorldCallback(String args, long commandTime){
//Callback triggered... Do something!
//For example, display a reference card:
sgmLib.sendReferenceCard("TitleText", "BodyText");
}