Entry point
In app logic, you mainly interact with a GlassesClient instance provided by the host app template.
The 0.3.0 generated API reference is published at https://hkust-spark.github.io/xg-glass-sdk/. It is generated from KDoc on every release and covers all 13 published modules: app-contract, core, core-android, device-even, device-frame-flutter, device-inmo-runtime, device-meta, device-omi, device-rayneo-installer, device-rayneo-runtime, device-rokid, device-simulator, and universal.
Operations
capturePhoto()(photo capture)display()(text display)displayImage()(PNG/JPEG image display)startMicrophone()(microphone capture)startVideoStream()(video frame streaming)events(log/warning/tap/long-press/battery event stream)capabilities(adapter feature flags such assupportsTapEvents,supportsLongPressEvents,supportsBatteryEvents,canDisplayImages, andcanStreamVideo)
Note: the SDK’s host app template owns the connection lifecycle and permissions UI. Your app logic typically focuses on the operations below.
Photo capture
val image = client.capturePhoto().getOrThrow()
val jpegBytes = image.jpegBytes
Text display
client.display("Hello from xg.glass").getOrThrow()
Image display
if (client.capabilities.canDisplayImages) {
client.displayImage(
DisplayImage(
bytes = pngOrJpegBytes,
encoding = ImageEncoding.PNG
)
).getOrThrow()
}
Microphone capture
val session = client.startMicrophone().getOrThrow()
// session.audio is a Flow<AudioChunk>; collect it and stop when done.
// ...
session.stop()
Video streaming
if (client.capabilities.canStreamVideo) {
val session = client.startVideoStream().getOrThrow()
try {
session.frames.collect { frame ->
if (!frame.endOfStream) handleVideoFrame(frame.bytes)
}
} finally {
session.stop()
}
}
The stream buffer keeps latency low with drop-oldest behavior, and VideoStreamSession.droppedFrameCount reports evicted frames. During an active stream, supported adapters can satisfy capturePhoto() from the latest streamed frame.
Events
client.events.collect { event ->
when (event) {
is GlassesEvent.BatteryLevel -> updateBattery(event.percent)
else -> Unit
}
}
Errors
SDK methods return Kotlin Result<T> values. The shared error hierarchy is GlassesError; current variants include NotConnected, PermissionDenied, Busy, Timeout(operation), Unsupported(detail), and Transport(detail, cause).