Develop

Application sample overview

Updated: Sep 5, 2026

Overview

This sample demonstrates the Application API in the Meta VR Platform SDK. It shows how to query app version information, launch other apps with deeplink options, and manage app downloads and updates on Meta Quest devices. View the sample source code on GitHub⁠.

What you will learn

  • Initialize the VR Platform SDK with HorizonServiceConnection.
  • Query app version information with Application.getVersion().
  • Launch other apps and Horizon Worlds destinations with Application.launchOtherApp().
  • Manage downloads and updates with startAppDownload(), checkAppDownloadProgress(), installAppUpdateAndRelaunch(), and cancelAppDownload().
  • Structure SDK calls with a repository, coroutine-based loading, and error states.

Requirements

  • Meta VR device with developer mode enabled
  • Android Studio (recommended: latest stable version)
  • Kotlin development environment
For detailed developer mode setup instructions, see Mobile device setup.

Get started

Clone the VR Platform SDK samples repository⁠ and open the 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.

Explore the sample

The sample uses MVVM architecture with a Jetpack Compose UI. An activity connects to the SDK and hosts the UI. A repository wraps the Application API. A ViewModel drives screen state.
FileWhat it demonstratesKey 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

Runtime behavior

When you run this sample, you see a screen titled PSDK Application Sample. The home screen shows a set of buttons. Each button calls one Application API and shows the result. Tap Get Version to query the current app version. Tap Launch Other App to open Beat Saber with a deeplink message and destination API name. Tap Launch Horizon World to open a Horizon Worlds destination. The download and update buttons (Start app download, Check app download progress, Install app update and relaunch, and Cancel app download) manage the download and update lifecycle. Each button shows a loading indicator while the call runs. It then displays the JSON result or an error message.

Key concepts

SDK initialization pattern

The sample initializes the VR Platform SDK in 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,
        )
    }
}

Repository and action wrapper

The 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.
See ApplicationRepository.kt and HomeViewModel.kt in the sample source⁠.

Builder pattern for API options

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().

Coroutine-based state management

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.

Extend the sample

  • Change the target app in launchOtherApp() to launch a different app by its application ID.
  • Try different deeplink messages and destination API names.
  • Replace the generic catch (Exception) block with handlers for specific ApplicationStatusCode values.