HorizonServiceConnectionStateFlowconsent 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.| File | What it demonstrates | Key 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 |
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.getConsentStatus() with a consent flow name:val status = consent.getConsentStatus(
flowName, null, emptyMap()
)
status[0].status. The Consent object itself is created with a no-argument constructor as a private property of the ViewModel.ConsentViewModel.kt.launchConsentIfRequired() with the same flow name:val result = consent.launchConsentIfRequired(
flowName, null, emptyMap()
)
result.outcome to determine whether the user completed the flow. Both API calls run on Dispatchers.IO inside a viewModelScope.launch block.ConsentViewModel.kt.DataStore or SharedPreferences.