Develop

Asset File sample overview

Updated: May 8, 2026

Overview

This sample demonstrates how to initialize the Horizon Platform SDK and instantiate the AssetFile service. The AssetFile API enables your app to manage downloadable content (DLC) — additional files such as expansion packs, level data, or media assets that users can download after installing your app, rather than bundling everything in the initial APK. The sample focuses on service setup and initialization verification — it does not demonstrate downloading, listing, or managing asset files. View the sample source code on GitHub.

What you will learn

  • Connect to the Horizon platform service using HorizonServiceConnection
  • Instantiate the AssetFile service class in a ViewModel
  • Verify that the AssetFile service initialized without errors
  • Structure SDK integration using MVVM architecture with Jetpack Compose
  • Handle SDK errors and surface them to users

Requirements

  • Meta Quest device
  • Android development environment
For complete setup instructions, including required SDK versions, toolchain details, and how to obtain your application ID, see the Horizon Platform SDK setup guide.

Get started

Clone the Horizon Platform SDK Samples repository and open the assetfile/ project in Android Studio. Before running the sample, replace the APPLICATION_ID property in MainActivity.kt with your application ID from the Meta Quest Developer Center. Connect your Quest device, build the project, and deploy to your device. The repository README contains build troubleshooting and advanced configuration options.

Explore the sample

FileWhat it demonstratesKey concepts
MainActivity.kt
SDK service connection and Compose UI setup
HorizonServiceConnection.connect(), Material3 Compose UI, accessibility semantics
AssetFileViewModel.kt
AssetFile service instantiation and initialization verification
ViewModel-scoped SDK object, coroutine-based error handling, reactive state management
app/build.gradle.kts
SDK dependency configuration
Horizon Platform SDK artifact (asset-file-kotlin:0.2.0), Kotlin version, compile/target SDK
libs.versions.toml
Version catalog for dependencies
Centralized version management, PSDK version pinning

Runtime behavior

When you run this sample, you see a single screen titled Asset File Sample with a description of the AssetFile service and a Check Initialization button. Tap the button to verify that the AssetFile service initialized successfully. The sample displays a success message in a card if initialization succeeds, or an error message if it fails.

Key concepts

Service connection pattern

The sample establishes a connection to the Horizon platform service before rendering any UI:
HorizonServiceConnection.connect(
    APPLICATION_ID,
    this@MainActivity.applicationContext,
    lifecycleScope,
)
See MainActivity.kt for the complete implementation.

ViewModel-scoped SDK object

The AssetFile instance is created as a class-level property in the ViewModel, ensuring it survives configuration changes:
private val assetFile = AssetFile()

IO dispatcher for SDK calls

All SDK-related work runs on Dispatchers.IO to avoid blocking the main thread:
viewModelScope.launch(Dispatchers.IO) {
    // SDK work here
}
See the checkInitialization() method in AssetFileViewModel.kt.

Reactive state management

The sample uses Kotlin StateFlow to expose UI state changes from the ViewModel. The UI observes state via collectAsStateWithLifecycle() and recomposes automatically when state updates:
val uiState by viewModel.uiState.collectAsStateWithLifecycle()

Extend the sample

  • List available asset files: Call AssetFile API methods to query downloadable content available for your application.
  • Download asset files: Implement download functionality with progress monitoring and status updates.
  • Manage local asset files: Add UI for deleting downloaded assets, checking file status, and managing storage.