Skip to main content
A minimal integration that loads a web-based identity journey inside a native Android app. This example compiles and runs as a standalone Jetpack Compose app.

What This Example Demonstrates

  • Initializing a BridgeHost with typed capability slots
  • Declaring document capture support via handler assignment
  • Displaying a journey by attaching a WebView in Compose
  • Observing bridge errors through a BridgeHostDelegate

Complete Source

How It Works

  1. BridgeHost(hostVersion = ...) creates a host with typed capability slots. No separate configuration object is needed. BridgeHost is main-thread-only, so construct it and call its methods on the main thread β€” composition already runs there.
  2. Setting a handler on documentCapture declares the capability as supported. The handler uses awaitCompletion() to suspend until the UI layer calls complete().
  3. CameraDetector.check(context) detects camera hardware and permission state. The permissionState is included in capability query responses.
  4. host.attach(webView) configures the WebView (enables JavaScript and DOM storage), installs a bootstrap-injecting WebViewClient, and registers the window.GBGBridge JavaScript interface. There is no BridgeWebView wrapper on Android β€” you create a plain WebView (here via AndroidView), attach it to the host, and call loadUrl() yourself.
  5. Error observation β€” unlike iOS, where host.lastError is @Published, the Android lastError property is not observable. Instead, implement BridgeHostDelegate.onError and mirror errors into Compose state. The host holds its delegate in a weak reference, so keep a strong reference to it (here via remember) or it will be garbage-collected and silently stop firing.
  6. DisposableEffect.onDispose calls host.detach() when the screen leaves composition. Detach cancels any in-flight capture, removes the JavaScript interface, and clears the message buffers, so the host is ready for a clean re-attach.

What Happens at Runtime

Required Project Configuration

To compile this example, add the SDK dependency to your module’s build.gradle.kts (no repository setup is needed beyond mavenCentral()):
The only manifest entry this minimal example needs is the Internet permission:
If your journey URL uses HTTP during development, note that Android blocks cleartext traffic by default. Add a network security configuration scoped to your local development hosts (from the emulator, your host machine is 10.0.2.2, not localhost):
Reference it from the manifest with android:networkSecurityConfig="@xml/network_security_config" on the <application> element. Never ship an unscoped android:usesCleartextTraffic="true" in production.

Next Steps