AbuseReport service and verify service availability using modern Android architecture patterns (MVVM with Jetpack Compose). View the sample source code on GitHub.HorizonServiceConnectionAbuseReport serviceStateFlowabusereport module in Android Studio. Before building, replace the APPLICATION_ID placeholder in MainActivity.kt with your Application ID from the Meta Horizon developer dashboard. If you haven’t created an app yet, follow the Horizon Platform SDK setup for Kotlin guide to register your app and obtain your Application ID. Connect your Meta Quest device via USB and run the sample. For detailed build instructions and dependency versions, see the sample’s README.| File | What it demonstrates | Key concepts |
|---|---|---|
MainActivity.kt | Entry point that establishes the Platform SDK connection and renders the Compose UI | SDK connection via HorizonServiceConnection.connect(), lifecycle-aware state collection |
AbuseReportViewModel.kt | Business logic for service verification and UI state management | AbuseReport instantiation, StateFlow-based reactive state, data class state modeling |
AbuseReportViewModelTest.kt | Unit tests for UI state data class behavior | Data class default values and copy() behavior verification |
app/build.gradle.kts | Gradle build configuration with SDK dependencies | Adding core-kotlin and abuse-report-kotlin SDK artifacts |
AbuseReport instance is available and displays either a success card confirming initialization or an error card if the check fails.onCreate():HorizonServiceConnection.connect(
APPLICATION_ID,
this@MainActivity.applicationContext,
lifecycleScope,
)
MainActivity.kt for the complete implementation.ViewModel creates an AbuseReport instance using the no-argument constructor:private val abuseReport = AbuseReport()
AbuseReport service provides a no-arg constructor that becomes usable after HorizonServiceConnection.connect() completes. The sample’s checkInitialization() method verifies availability by referencing the initialized instance. See AbuseReportViewModel.kt for the verification logic.StateFlow:data class AbuseReportUiState(
val isLoading: Boolean = false,
val resultMessage: String? = null,
val errorMessage: String? = null,
)
collectAsStateWithLifecycle(), which automatically starts and stops collection based on the activity lifecycle. See AbuseReportViewModel.kt for the state management implementation.AbuseReport API beyond initialization. See the Horizon Platform SDK documentation for available methods and their expected parameters.AbuseReport service alongside other Platform SDK services like GroupPresence or Leaderboard to see how multiple services coexist within a single ViewModel.