Develop

Device Application Integrity sample overview

Updated: May 8, 2026

Overview

This sample demonstrates how to initialize the Horizon Platform SDK and instantiate the DeviceApplicationIntegrity service class in an Android app for Meta Quest. It uses the MVVM architecture with Jetpack Compose to show SDK setup and service connection patterns. This sample demonstrates initialization and service readiness only — it does not call getIntegrityToken() or demonstrate actual integrity token generation. View the sample source code on GitHub.

What you will learn

  • Initialize the Horizon Platform SDK with HorizonServiceConnection.connect()
  • Instantiate the DeviceApplicationIntegrity service class
  • Structure a Platform SDK app using the MVVM pattern with Jetpack Compose
  • Manage loading and error states with StateFlow and Compose
  • Configure your application ID for Platform SDK services

Requirements

  • Meta Quest device with Developer Mode enabled
  • Android development environment (Android Studio recommended)
For complete development environment setup and SDK configuration, see the Platform SDK setup guide.

Get started

Clone or download the Horizon Platform SDK samples repository from GitHub and open the deviceapplicationintegrity project in Android Studio. Before running the sample, replace the APPLICATION_ID placeholder in MainActivity.kt with your app’s application ID from the Meta Quest Developer Dashboard. Build the project and deploy it to your Meta Quest device. For detailed build instructions, see the sample’s README.

Explore the sample

FileWhat it demonstratesKey concepts
MainActivity.kt
SDK initialization and Compose UI setup
HorizonServiceConnection.connect(), ComponentActivity, MaterialTheme
DeviceIntegrityViewModel.kt
Service instantiation and initialization check
DeviceApplicationIntegrity(), StateFlow, viewModelScope
DeviceIntegrityViewModelTest.kt
UI state data class testing
DeviceIntegrityUiState copy semantics

Runtime behavior

When you run the sample, you see a screen with the Device Integrity Sample heading and descriptive text. The screen displays a Check Initialization button. When you tap the button, a loading indicator appears briefly, then the app displays either a success card showing “DeviceApplicationIntegrity service initialized successfully.” or an error card with exception details.

Key concepts

Horizon Service connection

HorizonServiceConnection.connect() must be called before using any Platform SDK service. The sample calls it in MainActivity.onCreate() with the application ID, application context, and lifecycle scope.

Service instantiation

DeviceApplicationIntegrity() uses a no-arg constructor that internally resolves HorizonServiceConnection.instance. The sample constructs this service object as a class-level property in DeviceIntegrityViewModel, which means construction happens when the ViewModel is created. The checkInitialization() method verifies the service is ready by logging the instance and reporting success or failure to the UI.

State management

The sample uses a DeviceIntegrityUiState data class with three properties: isLoading, resultMessage, and errorMessage. The ViewModel exposes this state as a StateFlow, which the Compose UI observes using collectAsStateWithLifecycle().

Extend the sample

  • Call getIntegrityToken(challengeNonce) to request an actual integrity token. This requires SDK v0.2.1 or later, available on HzOS v85 or later.
  • Add server-side token verification to validate the JWT response and confirm device authenticity.
  • Handle specific DeviceApplicationIntegrityStatusCode values for granular error handling.
For the complete token request flow, see the Attestation API documentation.