HorizonServiceConnection.connect()richpresence/ folder in Android Studio, configure your Application ID following the setup guide, and run the app on your Meta Quest device.| File | What it demonstrates | Key concepts |
|---|---|---|
MainActivity.kt | SDK initialization and Compose UI | HorizonServiceConnection.connect(), collectAsStateWithLifecycle() |
RichPresenceViewModel.kt | Business logic and state management | RichPresence() API, coroutine-based async calls, StateFlow |
RichPresenceViewModelTest.kt | Unit testing UI state defaults | RichPresenceUiState data class verification |
build.gradle.kts | Dependencies and SDK versions | Horizon SDK artifacts, Compose configuration |
RichPresenceOptions using a fluent builder API:RichPresenceOptions.builder()
.withApiName(apiName)
.withDeeplinkMessageOverride(message)
.withIsJoinable(joinable)
.build()
getDestinations() method returns a paged result object. The sample fetches the initial page with fetchInitialPage().get(), then iterates through getFetchedPages() to access each page’s contents. Each destination object exposes a json property for serialization.ViewModel exposes UI state through a read-only StateFlow while updating a private MutableStateFlow internally. All SDK calls run in viewModelScope.launch(Dispatchers.IO) with try/catch blocks updating error state on failure.setPresence() to accept user input through text fields.getDestinations() to fetch and display additional pages.