sample-app-guide

tarafından facebook

Oturum oluşturma, kamera akışı ve fotoğraf çekimi ile eksiksiz bir DAT uygulaması oluşturma

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)
    }
}

DeviceSession.start() is fire-and-forget. Attach the camera from the session-state collector once the session reports DeviceSessionState.STARTED; adding a capability to an IDLE session fails with DeviceSessionError.SESSION_IDLE.

class SessionViewModel : ViewModel() {
    private var session: DeviceSession? = null
    private var camera: Camera? = null

    fun startCameraSession() {
        Wearables.createSession(AutoDeviceSelector()).fold(
            onSuccess = { createdSession ->
                session = createdSession

                viewModelScope.launch {
                    createdSession.errors.collect { error -> showError(error.description) }
                }
                viewModelScope.launch {
                    createdSession.state.collect { state ->
                        when (state) {
                            DeviceSessionState.STARTED -> attachCamera(createdSession)
                            DeviceSessionState.STOPPED -> clearSession(createdSession)
                            else -> Unit
                        }
                    }
                }

                createdSession.start()
            },
            onFailure = { error, _ -> showError(error.description) },
        )
    }

    private fun attachCamera(activeSession: DeviceSession) {
        if (camera != null) return
        activeSession.addCamera(
            StreamConfiguration(videoQuality = VideoQuality.MEDIUM, frameRate = 24),
        ).fold(
            onSuccess = { addedCamera ->
                camera = addedCamera
                addedCamera.stream.start().onFailure { error, _ ->
                    showError(error.description)
                }
            },
            onFailure = { error, _ -> showError(error.description) },
        )
    }

    private fun clearSession(stoppedSession: DeviceSession) {
        if (session !== stoppedSession) return
        camera = null
        session = null
    }
}

Observe frames and capture photos

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

fun capturePhoto() {
    viewModelScope.launch {
        camera?.stream?.capturePhoto()
            ?.onSuccess { photoData ->
                when (photoData) {
                    is PhotoData.Bitmap -> savePhoto(photoData.bitmap)
                    is PhotoData.HEIC -> saveHeic(photoData.data)
                }
            }
            ?.onFailure { error, _ ->
                showCaptureError(error.description)
            }
    }
}

Shutdown

fun stopCameraSession() {
    camera?.stop()
    session?.stop()
    camera = 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

facebook tarafından daha fazla skill

gc-safe-coding
facebook
Tam açıklama ve gerekçe için doc/GCSafeCoding.md dosyasına bakın.
app-review-prep
facebook
Meta uygulamasını App Review için hazırlayın — mevcut durumu, bekleyen gereksinimleri, verilen ayrıcalıkları ve gönderim geçmişini kontrol eder. Bir uygulama göndermeden önce kullanın…
api-health
facebook
Bir Meta uygulaması için API sağlığını izleyin — hız sınırlarını, çağrı hacmini ve API kullanımdan kaldırmalarını kontrol edin. Azaltmayı teşhis etmek, kapasite planlamak veya API sürümüne hazırlanmak için kullanın…
debug-webhooks
facebook
Meta uygulaması için webhook sorunlarını giderin — aktif abonelikleri inceleyin, yanlış yapılandırmayı tespit edin ve teslimatı doğrulamak için test yükleri gönderin. Şu durumlarda kullanın…
api-integration
facebook
Bir geliştiriciyi sıfırdan Meta API entegrasyonu kurma konusunda yönlendirir — doğru API'leri keşfeder, kurulum kılavuzlarını getirir, kimlik doğrulama gereksinimlerini kontrol eder,…
webhook-setup
facebook
Bir Meta uygulaması için webhook'ları uçtan uca kurun — mevcut konuları keşfedin, alanlara abone olun ve bir test payload'ı ile doğrulayın. Webhook yapılandırırken kullanın…
test-ui
facebook
Test UI sistemini (PanelUI, ScreenSpace) poke örneğine karşı iwsdk CLI kullanarak test edin.
flags
facebook
React sürüm kanalları arasında özellik bayrağı durumlarını inceleyin ve karşılaştırın. Tüm bayrakları kanallar arasında (www, www-modern, canary, next, experimental, rn varyantları) görüntüleyin veya --diff ile belirli kanalları karşılaştırın. Çıktı biçimleri varsayılan tablo görünümü, CSV dışa aktarma ve temizlik durumu gruplandırmasını içerir. Bayrak durumları sembollerle gösterilir: etkin (✅), devre dışı (❌), varyant testi (🧪), yalnızca profil oluşturma (📊). Yaygın tuzak: __VARIANT__ bayrakları www üzerinde her iki durumda da test edilir; anlamlı farklılı