HorizonServiceConnection.connect()UserAgeCategory.get() API and handle its asynchronous responseAccountAgeCategory enum values to user-facing stringsuseragecategory project in Android Studio. Replace the APPLICATION_ID property in MainActivity.kt with your app’s Horizon application ID. Connect your Meta Quest device via adb with Developer Mode enabled, then run the sample from Android Studio. For detailed build instructions, see the sample README.| File | What it demonstrates | Key concepts |
|---|---|---|
MainActivity.kt | SDK initialization and Compose UI setup | HorizonServiceConnection.connect(), Compose integration, application ID configuration |
UserAgeCategoryViewModel.kt | SDK API invocation and state management | UserAgeCategory.get() usage, coroutine-based async calls, StateFlow for UI state |
libs.versions.toml | SDK dependency declaration | Maven coordinates for user-age-category-kotlin and core-kotlin artifacts |
UserAgeCategory API is instantiated with a no-arg constructor and called on a background dispatcher:val result = userAgeCategory.get() val category = result.ageCategory
AccountAgeCategory enum has four values: Ch (Child), Tn (Teen), Ad (Adult), and Unknown. The sample uses an exhaustive when expression:when (category) {
AccountAgeCategory.Ch -> "Child"
AccountAgeCategory.Tn -> "Teen"
AccountAgeCategory.Ad -> "Adult"
AccountAgeCategory.Unknown -> "Unknown"
}
StateFlow<UserAgeCategoryUiState> to drive the Compose UI. The ViewModel emits state updates for loading, success, and error conditions, and the UI collects the flow using collectAsStateWithLifecycle().when block to show age-appropriate content or features based on the retrieved category.SharedPreferences or a local database.