Develop

Abuse Report sample overview

Updated: May 8, 2026

Overview

This sample demonstrates how to initialize the Horizon Platform SDK’s AbuseReport service and verify service availability using modern Android architecture patterns (MVVM with Jetpack Compose). View the sample source code on GitHub.

What you will learn

  • Connect to the Horizon Platform SDK using HorizonServiceConnection
  • Instantiate and verify the AbuseReport service
  • Structure Platform SDK integration using MVVM and StateFlow
  • Observe Platform SDK state updates in Compose using lifecycle-aware collection
  • Configure the required SDK dependencies in your build file

Requirements

  • Development environment: Android Studio with Kotlin 2.0 support
  • Target device: Meta Quest device with Android API 34+
  • Platform SDK setup: Complete the Horizon Platform SDK setup for Kotlin before running this sample

Get started

Clone the horizon-platform-sdk-samples repository and open the abusereport 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.

Explore the sample

The following table describes the key files in this sample and what each one demonstrates:
FileWhat it demonstratesKey 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

Runtime behavior

When you run this sample, you see a screen with the title Abuse Report Sample and a description explaining the sample’s purpose. A Check Initialization button appears below the description. When you tap the button, the sample verifies that the AbuseReport instance is available and displays either a success card confirming initialization or an error card if the check fails.

Key concepts

Platform SDK connection

The sample establishes the Horizon Platform SDK connection in onCreate():
HorizonServiceConnection.connect(
    APPLICATION_ID,
    this@MainActivity.applicationContext,
    lifecycleScope,
)
The sample passes the Application ID, application context, and activity’s lifecycle scope. The sample establishes this connection before accessing any Platform SDK services. See MainActivity.kt for the complete implementation.

AbuseReport service instantiation

The ViewModel creates an AbuseReport instance using the no-argument constructor:
private val abuseReport = AbuseReport()
The 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.

Reactive UI state with StateFlow

The sample models UI state as an immutable data class exposed via StateFlow:
data class AbuseReportUiState(
    val isLoading: Boolean = false,
    val resultMessage: String? = null,
    val errorMessage: String? = null,
)
The Compose UI observes state changes using collectAsStateWithLifecycle(), which automatically starts and stops collection based on the activity lifecycle. See AbuseReportViewModel.kt for the state management implementation.

Extend the sample

  • Add event handling: Explore the AbuseReport API beyond initialization. See the Horizon Platform SDK documentation for available methods and their expected parameters.
  • Integrate multiple services: Add the AbuseReport service alongside other Platform SDK services like GroupPresence or Leaderboard to see how multiple services coexist within a single ViewModel.
  • Test error handling: Try running with an invalid Application ID or without completing SDK setup to understand error handling patterns. Observe the error messages in the UI to learn what exceptions the SDK throws for different failure modes.