Develop

Consent sample overview

Updated: May 8, 2026

Overview

This sample demonstrates how to check and request user consent using the Horizon Platform SDK. The app shows how to query the current consent status for a given flow and launch the consent UI when required, using the Consent API with Jetpack Compose and Kotlin coroutines. View the sample source code on GitHub.

What you will learn

  • Initialize the Horizon Platform SDK with HorizonServiceConnection
  • Check consent status for a specific flow
  • Launch the consent UI when user consent is required
  • Structure an MVVM-based app with coroutines and StateFlow
  • Handle consent API responses and display results in a Compose UI

Requirements

  • A Meta Quest device running Android 14 or higher
  • Android Studio with Kotlin 2.0+ support
  • A Horizon Platform Application ID
For setup instructions, see Platform SDK setup for Kotlin.

Get started

Clone the Horizon Platform SDK samples repository and open the consent directory in Android Studio. Before building, replace the APPLICATION_ID placeholder in MainActivity.kt with your own Application ID from the Horizon Platform developer dashboard. The sample uses Gradle version catalogs for dependency management, so sync the project to download the required SDK artifacts: core-kotlin and consent-kotlin. For complete build and deployment instructions, see the repository README.

Explore the sample

FileWhat it demonstratesKey concepts
MainActivity.kt
Establishes the Horizon service connection and defines the Compose UI with input field and action buttons
HorizonServiceConnection.connect(), Material3 components
ConsentViewModel.kt
Manages UI state and executes consent API calls on a background dispatcher
Consent() instantiation, Dispatchers.IO, StateFlow
ConsentViewModelTest.kt
Unit tests verifying UiState data class defaults and copy semantics
Data class immutability
build.gradle.kts
Declares SDK dependencies with minSdk 34 and targetSdk 36
consent-kotlin artifact

Runtime behavior

When you launch the app, you see a text field pre-populated with the consent flow name rl_social_privacy_setting_dedup and two buttons. Tapping Get Consent Status queries the current consent state for that flow and displays the result in a card below. Tapping Launch Consent If Required triggers the system consent UI if needed, then shows the outcome. A loading spinner appears during API calls, and errors display in a red-tinted card.

Key concepts

The sample queries consent status by calling getConsentStatus() with a consent flow name:
val status = consent.getConsentStatus(
    flowName, null, emptyMap()
)
The method returns a list, and the sample reads the result from the first element via status[0].status. The Consent object itself is created with a no-argument constructor as a private property of the ViewModel.
When the user taps Launch Consent If Required, the sample calls launchConsentIfRequired() with the same flow name:
val result = consent.launchConsentIfRequired(
    flowName, null, emptyMap()
)
This method triggers the system consent UI if the user has not yet consented and returns a result object. The sample reads result.outcome to determine whether the user completed the flow. Both API calls run on Dispatchers.IO inside a viewModelScope.launch block.

Extend the sample

  • Test multiple consent flows: Replace the default flow name with consent flow identifiers from your Horizon Platform configuration.
  • Add flow selection: Create a dropdown or list of predefined consent flows instead of a text input field.
  • Persist consent state: Store consent status results locally using DataStore or SharedPreferences.