Session state, stream state, pause and resume behavior, and device availability monitoring
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "session-lifecycle" 技能: 1. 下载 https://raw.githubusercontent.com/facebook/meta-wearables-dat-android/main/plugins/mwdat-android/skills/session-lifecycle/SKILL.md 2. 保存为 ~/.claude/skills/session-lifecycle/SKILL.md 3. 装好后重载技能,告诉我可以用了
Manage session and stream state in DAT SDK integrations.
Create a Session with Wearables.createSession(...), start it, then attach capabilities such as camera streaming. Session lifecycle and stream lifecycle are related but distinct.
| State | Meaning | App action |
|---|---|---|
IDLE | Session created, not started yet | Call session.start() |
STARTING | Connecting to the device | Show loading UI |
STARTED | Session active and ready for capabilities | Add or use capabilities |
PAUSED | Session temporarily suspended | Keep state, wait for resume or stop |
STOPPING | Session is shutting down | Stop user work and wait |
STOPPED | Session ended | Release resources and create a new session if needed |
val session = Wearables.createSession(AutoDeviceSelector()).getOrElse { error ->
throw IllegalStateException(error.description)
}
session.start()
lifecycleScope.launch {
session.state.collect { state ->
when (state) {
DeviceSessionState.STARTED -> onStarted()
DeviceSessionState.PAUSED -> onPaused()
DeviceSessionState.STOPPED -> onStopped()
else -> Unit
}
}
}
Camera streaming has its own state flow after you attach a stream:
STOPPED -> STARTING -> STARTED -> STREAMING -> STOPPING -> STOPPED -> CLOSED
lifecycleScope.launch {
stream.state.collect { state ->
// React to camera capability state changes
}
}
The SDK may pause or stop a session when:
When a session is paused:
lifecycleScope.launch {
Wearables.devices.collect { devices ->
// Update the list of available devices
}
}
Use Wearables.devices and device metadata to decide when it is sensible to create a new session after a stop.
DeviceSessionState values you care aboutSessionError and StreamError failuresSession and Stream capability setup, video frames, photo capture, resolution and frame rate configuration
Kotlin patterns, DatResult, session and capability conventions for DAT SDK Android development
Common issues, Developer Mode, version compatibility, and session and stream diagnosis
Display capability setup, display-capable device selection, UI DSL, icons, buttons, images, and video playback
SDK setup, Gradle integration, AndroidManifest configuration, and first connection to Meta glasses
MockDeviceKit for testing without physical glasses hardware