Achievements service object for Meta Horizon Platform SDK integration in a Kotlin-based Android application. The sample is a minimal stub that focuses exclusively on service connection patterns and does not demonstrate achievement operations such as unlocking, querying definitions, or tracking progress.HorizonServiceConnection.connect()Achievements service objectStateFlowachievements/ directory in Android Studio. Before exploring the code on-device, replace the APPLICATION_ID placeholder in MainActivity.kt with your application ID from the Meta Developer Dashboard — skipping this step causes the app to crash with IllegalStateException. For complete dependency and build information, see the sample’s README.| File | What it demonstrates | Key concepts |
|---|---|---|
MainActivity.kt | SDK initialization via HorizonServiceConnection.connect(), Compose UI entry point | Application ID configuration, lifecycle scope integration, exception handling for missing credentials |
AchievementsViewModel.kt | Achievements() service instantiation, initialization verification, UI state management | No-arg constructor pattern, StateFlow-based tri-state loading pattern (loading/success/error), coroutine-based initialization check |
AchievementsViewModelTest.kt | Unit tests for AchievementsUiState data class | Data class property validation, default state testing |
app/build.gradle.kts | SDK dependency configuration | Artifact declaration for com.meta.horizon.platform.sdk:achievements-kotlin:0.2.0 |
HorizonServiceConnection.connect() with three parameters: application ID, application context, and a coroutine scope (typically lifecycleScope). SDK service objects require a successful connection before they can be used.HorizonServiceConnection.connect(APPLICATION_ID, applicationContext, lifecycleScope)
MainActivity.kt for the complete implementation.Achievements service uses a no-arg constructor. The sample instantiates it as a ViewModel property and verifies initialization by calling toString() on the object.private val achievements = Achievements()
AchievementsViewModel.kt for the complete implementation.AchievementsUiState, a data class with isLoading, resultMessage, and errorMessage properties. The ViewModel exposes state via StateFlow, and the composable UI collects it using collectAsStateWithLifecycle().data class AchievementsUiState(
val isLoading: Boolean = false,
val resultMessage: String? = null,
val errorMessage: String? = null,
)
AchievementsViewModel.kt for the complete implementation.