Terminal
Terminal/Skill
Kotlin coding patterns, result types and naming rules for building Android apps with the Meta Wearables Device Access Toolkit.
By Meta
Works with
npx skills add facebook/meta-wearables-dat-android --skill dat-conventions| Task | Command |
|---|---|
| Build app | ./gradlew assembleDebug |
| Run tests | ./gradlew test |
| Install app | ./gradlew installDebug |
| Lint app | ./gradlew lint |
The SDK is organized into four public modules:
DeviceSession.start() is fire-and-forget and returns Unit; capabilities can only be attached once the session reports DeviceSessionState.STARTED.
Wearables.initialize(context)
Wearables.createSession(AutoDeviceSelector()).fold(
onSuccess = { session ->
lifecycleScope.launch {
session.state.collect { state ->
if (state == DeviceSessionState.STARTED) {
session.addCamera(StreamConfiguration()).fold(
onSuccess = { camera ->
camera.stream.start().onFailure { error, _ ->
showError(error.description)
}
},
onFailure = { error, _ -> showError(error.description) },
)
}
}
}
lifecycleScope.launch {
session.errors.collect { error -> showError(error.description) }
}
session.start()
},
onFailure = { error, _ -> showError(error.description) },
)
DatResult<T, E> for typed success and failure handlingfold, onSuccess, and the two-parameter onFailure { error, cause -> } overload, which hands you the typed DatError with a descriptiongetOrElse { } receives a raw Throwable, not a typed DatError, so it cannot read error.descriptionStateFlow and FlowDeviceSession first, then attach capabilities such as Camera or Display after it reaches STARTEDWearables.checkPermissionStatus(Permission.CAMERA)
.onSuccess { status -> /* handle status */ }
.onFailure { error, _ -> /* handle error */ }
Avoid getOrThrow() in user-facing samples. Surface typed errors from DatResult instead.
| Type | Purpose | Example |
|---|---|---|
DeviceSession | Device connection lifecycle | Wearables.createSession(...) |
Camera | Camera capability on a session | session.addCamera(...) |
Stream | Video stream from a camera | camera.stream |
Display | Display capability on a session | session.addDisplay(...) |
*Selector | Device targeting | AutoDeviceSelector, SpecificDeviceSelector |
*Error | Typed failure surface | DeviceSessionError, StreamError, CaptureError |
Wearables — SDK entry pointDeviceSession — lifecycle for an interaction with a linked deviceCamera — camera capability attached to a sessionStream — video stream accessed through camera.streamDisplay — display capability attached to a sessionStreamConfiguration — video quality, frame rate, and compression configurationMockDeviceKit — simulated device environment for testingIf your editor supports remote MCP servers, connect https://mcp.developer.meta.com/wearables and use search_dat_docs for current DAT setup, session lifecycle, camera streaming, MockDeviceKit, permissions, and exact API symbols. This public docs server does not require authentication; do not configure tokens, OAuth, or custom authorization headers for it.
See the dat-docs-mcp skill for client setup and troubleshooting. Use llms.txt when your tool only supports static reference context.
val mockDeviceKit = MockDeviceKit.getInstance(context)
mockDeviceKit.enable()
mockDeviceKit.pairGlasses(GlassesModel.RAYBAN_META).fold(
onSuccess = { device -> onMockDevicePaired(device) },
onFailure = { error, _ -> showError(error.description) },
)
Use MockDeviceKit to drive registration, device availability, streaming media, and permission scenarios without physical hardware.
Wearables.initialize(context)addCamera(...) or addDisplay() immediately after session.start(); wait for DeviceSessionState.STARTEDDatResult failures from createSession, start, addCamera, addDisplay, or capturePhoto