sample-app-guide

โดย facebook

การสร้างแอป DAT ที่สมบูรณ์ด้วยการสร้างเซสชัน การสตรีมกล้อง และการถ่ายภาพ

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

Skills เพิ่มเติมจาก facebook

gc-safe-coding
facebook
สำหรับคำอธิบายและเหตุผลโดยละเอียด โปรดดูที่ doc/GCSafeCoding.md
app-review-prep
facebook
เตรียมแอป Meta สำหรับ App Review — ตรวจสอบสถานะปัจจุบัน ข้อกำหนดที่ค้างอยู่ สิทธิ์ที่ได้รับ และประวัติการส่ง ใช้ก่อนส่งแอป…
api-health
facebook
ตรวจสอบสุขภาพ API สำหรับแอป Meta — ตรวจสอบ rate limits, ปริมาณการเรียกใช้ และการเลิกใช้งาน API ใช้เพื่อวินิจฉัยการจำกัดการใช้งาน, วางแผนความจุ หรือเตรียมพร้อมสำหรับเวอร์ชัน API…
debug-webhooks
facebook
แก้ไขปัญหาเว็บฮุคสำหรับแอป Meta — ตรวจสอบการสมัครใช้งานที่ใช้งานอยู่ ระบุการตั้งค่าที่ผิดพลาด และส่งเพย์โหลดทดสอบเพื่อยืนยันการส่งมอบ ใช้เมื่อ…
api-integration
facebook
แนะนำนักพัฒนาในการตั้งค่าการเชื่อมต่อ Meta API ตั้งแต่เริ่มต้น — ค้นหา API ที่เหมาะสม ดึงคู่มือการตั้งค่า ข้อกำหนดการยืนยันตัวตน…
webhook-setup
facebook
ตั้งค่าเว็บฮุคสำหรับแอป Meta แบบครบวงจร — ค้นหาหัวข้อที่มีให้เลือก สมัครรับฟิลด์ และตรวจสอบด้วยเพย์โหลดทดสอบ ใช้เมื่อกำหนดค่าเว็บฮุคสำหรับ…
test-ui
facebook
ทดสอบระบบ UI (PanelUI, ScreenSpace) กับตัวอย่าง poke โดยใช้ iwsdk CLI
flags
facebook
ตรวจสอบและเปรียบเทียบสถานะฟีเจอร์แฟลกข้ามช่องทางการเผยแพร่ของ React ดูแฟลกทั้งหมดในทุกช่องทาง (www, www-modern, canary, next, experimental, rn variants) หรือเปรียบเทียบเฉพาะช่องทางด้วย --diff รูปแบบผลลัพธ์ประกอบด้วยมุมมองตารางเริ่มต้น, การส่งออก CSV, และการจัดกลุ่มสถานะการทำความสะอาด สถานะแฟลกแสดงด้วยสัญลักษณ์: เปิดใช้งาน (✅), ปิดใช้งาน (❌), ทดสอบรูปแบบต่างๆ (🧪), เฉพาะการทำโปรไฟล์ (📊) ข้อผิดพลาดทั่วไป: แฟลก __VARIANT__ ถูกทดสอบในทั้งสองสถานะบน www; ใช้ --diff เพื่อค้นหาความหมาย...