getting-started

โดย facebook

การตั้งค่า SDK, การรวม Gradle, การกำหนดค่า AndroidManifest, และการเชื่อมต่อครั้งแรกกับแว่นตา Meta

npx skills add https://github.com/facebook/meta-wearables-dat-android --skill getting-started

Getting Started with DAT SDK (Android)

Set up the Meta Wearables Device Access Toolkit in an Android app.

Prerequisites

  • Android Studio Flamingo or newer
  • Android 10+ test device with the Meta AI app installed
  • Supported Meta glasses or MockDeviceKit for local testing
  • Developer Mode enabled in the Meta AI app for development builds

The SDK is published to Maven Central under the com.meta.wearable group, so the mavenCentral() repository already declared in settings.gradle.kts is all that is needed. No access token is required.

Step 1: Declare dependencies

In libs.versions.toml:

[versions]
mwdat = "1.0.0"

[libraries]
mwdat-core = { group = "com.meta.wearable", name = "mwdat-core", version.ref = "mwdat" }
mwdat-camera = { group = "com.meta.wearable", name = "mwdat-camera", version.ref = "mwdat" }
mwdat-display = { group = "com.meta.wearable", name = "mwdat-display", version.ref = "mwdat" }
mwdat-mockdevice = { group = "com.meta.wearable", name = "mwdat-mockdevice", version.ref = "mwdat" }

In app/build.gradle.kts:

android {
    defaultConfig {
        manifestPlaceholders["mwdat_application_id"] = "0"
        manifestPlaceholders["mwdat_client_token"] = "0"
    }
}

dependencies {
    implementation(libs.mwdat.core)
    implementation(libs.mwdat.camera)
    implementation(libs.mwdat.display)
    implementation(libs.mwdat.mockdevice)
}

Step 2: Configure AndroidManifest.xml

<manifest ...>
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application ...>
        <meta-data
            android:name="com.meta.wearable.mwdat.APPLICATION_ID"
            android:value="${mwdat_application_id}" />
        <meta-data
            android:name="com.meta.wearable.mwdat.CLIENT_TOKEN"
            android:value="${mwdat_client_token}" />

        <activity android:name=".MainActivity" ...>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="myexampleapp" />
            </intent-filter>
        </activity>
    </application>
</manifest>

APPLICATION_ID and CLIENT_TOKEN are used for app attestation and can be found in the Wearables Developer Center. In Developer Mode, attestation is not used, so the manifest placeholders can both be 0. For production, replace both placeholders with the credentials for your Wearables Developer Center app. Replace myexampleapp with your app's URL scheme.

Step 3: Initialize the SDK

import android.util.Log
import com.meta.wearable.dat.core.Wearables

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        Wearables.initialize(this)
            .onFailure { error, _ ->
                Log.e("DATWearables", "Failed to initialize DAT: ${error.description}")
            }
    }
}

Step 4: Register and create a session

Registration must complete before a session can start. Observe Wearables.registrationState and wait for RegistrationState.REGISTERED.

import com.meta.wearable.dat.core.Wearables
import com.meta.wearable.dat.core.selectors.AutoDeviceSelector
import com.meta.wearable.dat.core.session.DeviceSession
import com.meta.wearable.dat.core.session.DeviceSessionState

fun connect(activity: Activity) {
    Wearables.startRegistration(activity)
}

fun startSession() {
    Wearables.createSession(AutoDeviceSelector()).fold(
        onSuccess = { session ->
            lifecycleScope.launch {
                session.errors.collect { error -> showError(error.description) }
            }
            lifecycleScope.launch {
                session.state.collect { state ->
                    if (state == DeviceSessionState.STARTED) {
                        addCameraStreaming(session)
                    }
                }
            }
            // Fire-and-forget: returns Unit and reports failures through session.errors.
            session.start()
        },
        onFailure = { error, _ -> showError(error.description) },
    )
}

Observe registration and available devices:

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

lifecycleScope.launch {
    Wearables.devices.collect { devices ->
        // Update the device list
    }
}

Step 5: Add camera streaming

Call this only once the session reports DeviceSessionState.STARTED; adding a capability earlier fails with DeviceSessionError.SESSION_IDLE.

import com.meta.wearable.dat.camera.addCamera
import com.meta.wearable.dat.camera.types.StreamConfiguration
import com.meta.wearable.dat.camera.types.VideoQuality

fun addCameraStreaming(session: DeviceSession) {
    session.addCamera(
        StreamConfiguration(videoQuality = VideoQuality.MEDIUM, frameRate = 24),
    ).fold(
        onSuccess = { camera ->
            camera.stream.start().onFailure { error, _ -> showError(error.description) }
        },
        onFailure = { error, _ -> showError(error.description) },
    )
}

Camera access also needs the DAT camera permission; see the permissions-registration skill.

Next steps

  • camera-streaming — Stream capability, video frames, photo capture
  • mockdevice-testing — Test without hardware
  • session-lifecycle — Handle session and stream state changes
  • permissions-registration — Registration and permission flows
  • display-access — Render content on Meta Ray-Ban Display glasses
  • Full Android API reference

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 เพื่อค้นหาความหมาย...