sample-app-guide

Building a complete DAT app with session creation, camera streaming, and photo capture

npx skills add https://github.com/facebook/meta-wearables-dat-android --skill sample-app-guide

Sample App Guide (Android)

Build an Android DAT app with registration, sessions, camera streaming, and photo capture.

Pair this with the CameraAccess sample.

Project setup

  1. Create an Android Studio app project.
  2. Add the DAT Maven repository and dependencies.
  3. Configure AndroidManifest.xml for registration callbacks plus APPLICATION_ID and CLIENT_TOKEN.
  4. Initialize Wearables in your Application.

Suggested app structure

app/src/main/java/com/example/myapp/
├── MyApplication.kt
├── MainActivity.kt
├── session/
│   └── SessionViewModel.kt
└── ui/
    ├── RegistrationScreen.kt
    └── CameraScreen.kt

Registration and session creation

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        lifecycleScope.launch {
            Wearables.registrationState.collect { state ->
                // Update registration UI
            }
        }
    }

    fun register() {
        Wearables.startRegistration(this)
    }
}
class SessionViewModel : ViewModel() {
    private var session: Session? = null
    private var stream: Stream? = null

    fun startCameraSession() {
        val createdSession = Wearables.createSession(AutoDeviceSelector()).getOrElse { error ->
            throw IllegalStateException(error.description)
        }
        createdSession.start()
        session = createdSession

        stream = createdSession.addStream(
            StreamConfiguration(videoQuality = VideoQuality.MEDIUM, frameRate = 24),
        ).getOrElse { error ->
            throw IllegalStateException(error.description)
        }.also { addedStream ->
            addedStream.start().getOrElse { error ->
                throw IllegalStateException(error.description)
            }
        }
    }
}

Observe frames and capture photos

viewModelScope.launch {
    stream?.videoStream?.collect { frame ->
        // Render preview
    }
}

fun capturePhoto() {
    viewModelScope.launch {
        stream?.capturePhoto()
            ?.onSuccess { photoData ->
                savePhoto(photoData.data)
            }
            ?.onFailure { error, _ ->
                showCaptureError(error.description)
            }
    }
}

Shutdown

fun stopCameraSession() {
    stream?.stop()
    session?.stop()
    stream = null
    session = null
}

Testing with MockDeviceKit

Use MockDeviceKit to simulate linking glasses, permission state, and camera media without physical hardware. See MockDevice Testing for setup details.

Links

More skills from facebook

binary-size-analysis
facebook
Analyze per-commit binary size changes of the hermesvm shared library across a git commit range. Produces a markdown report with per-commit sizes and summary tables of significant increases and decreases.
official
modify-jsi-features
facebook
Guide for adding new JSI functionality to the JavaScript Interface (JSI) layer. Use when the user asks to add, create, or implement new methods or features in…
official
non-interactive-git-rebase
facebook
Use when needing to reorder, split, drop, or amend git commits that are not the top commit, without interactive editor access. Covers programmatic rebase via…
official
click-target
facebook
Find and click a target object in XR. Use when testing UI interactions, clicking buttons, or verifying interactable elements work correctly.
official
iwsdk-planner
facebook
IWSDK project planning and best practices guide. Use when planning new IWSDK features, designing systems/components, reviewing IWSDK code architecture, or when…
official
iwsdk-ui-panel
facebook
Develop and iterate on IWSDK UI panels efficiently. Use when working on PanelUI components, debugging UI layout, or improving UI design in IWSDK applications.
official
test-all
facebook
Parallel test orchestrator. Runs all 9 test suites concurrently via Task sub-agents and the iwsdk CLI. Handles build, example setup, dev servers, agent launch,…
official
test-audio
facebook
Test audio system (AudioSource loading, playback state, stop, spatial audio) against the audio example using the iwsdk CLI.
official