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.HorizonServiceConnection.connect()DeviceApplicationIntegrity service classStateFlow and Composedeviceapplicationintegrity 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.| File | What it demonstrates | Key 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 |
DeviceApplicationIntegrity service initialized successfully.” or an error card with exception details.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.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.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().getIntegrityToken(challengeNonce) to request an actual integrity token. This requires SDK v0.2.1 or later, available on HzOS v85 or later.DeviceApplicationIntegrityStatusCode values for granular error handling.