HorizonServiceConnection.Application.getVersion().Application.launchOtherApp().startAppDownload(), checkAppDownloadProgress(), installAppUpdateAndRelaunch(), and cancelAppDownload().application project in Android Studio. The sample sets a test APPLICATION_ID in PsdkApplicationActivity.kt. Replace it with your own application ID from the Meta Developer Dashboard. Build the project and deploy it to your Meta Quest device via ADB. For complete build instructions and version requirements, see the sample’s README.ViewModel drives screen state.| File | What it demonstrates | Key concepts |
|---|---|---|
PsdkApplicationActivity.kt | SDK initialization and UI entry point | HorizonServiceConnection.connect(), Compose setup, state collection with collectAsStateWithLifecycle() |
repo/ApplicationRepository.kt | Application API usage | Application() instantiation, coroutine SDK calls on Dispatchers.IO, ApplicationOptions.builder() |
screens/HomeViewModel.kt | Screen state management | MutableStateFlow<HomeUiModel>, viewModelScope, the applicationAction wrapper |
screens/HomeScreen.kt | Compose UI and button actions | StateFlow collection, one button per API |
PsdkApplicationActivity.onCreate() before it sets up the Compose UI. HorizonServiceConnection.connect() takes three arguments: your application ID, the application context, and a coroutine scope (the activity’s lifecycleScope). The sample runs the connect call on Dispatchers.IO. This pattern is shared across all VR Platform SDK samples.lifecycleScope.launch {
withContext(Dispatchers.IO) {
HorizonServiceConnection.connect(
APPLICATION_ID,
applicationContext,
lifecycleScope,
)
}
}
ApplicationRepository instantiates Application() and exposes one suspend function per API. HomeViewModel wraps each call with a private applicationAction helper. The helper sets a loading flag, runs the repository call on Dispatchers.IO, and stores the JSON result or error in the UI state. This keeps loading and error handling in one place instead of repeating it per API.ApplicationRepository.launchOtherApp() shows the options pattern used across the VR Platform SDK. The sample calls ApplicationOptions.builder() to set a deeplink message and destination API name, then calls .build() to create the immutable options object. It passes those options to Application.launchOtherApp().HomeViewModel holds UI state in a MutableStateFlow<HomeUiModel> and exposes it as an immutable StateFlow. The Compose UI collects the flow with collectAsStateWithLifecycle(). Collection survives configuration changes and stops with the lifecycle. All SDK calls launch in viewModelScope on Dispatchers.IO to keep the main thread responsive.launchOtherApp() to launch a different app by its application ID.catch (Exception) block with handlers for specific ApplicationStatusCode values.