Docs › Recipes
Android (Kotlin)
The ScreenlyyID Android example is the reference for a native Android app. It mirrors the iOS example and has the same two parts, and the split matters:
backend/: a small Node server that holds the API key and theCorrelationIdand makes every ScreenlyyID call. You can swap it for your own server, for instance the Express or FastAPI recipes, which have the same two routes.app/: the Kotlin app. It contains no API key and no third-party libraries. It asks the back end to create a verification, asks for camera permission, opens thewebEnrolmentUrlin aWebView, listens forIDV_SESSION_COMPLETEandERROR, then asks the back end for the result.
Follow the steps and the camera-permission notes on the Mobile app page. The example's README explains how to run both parts on an emulator or a real phone.
The two Android details#
These are the usual reasons capture "does nothing" on Android:
- Grant the page's camera request. The capture page asks the
WebViewfor the camera, and theWebViewonly provides it if yourWebChromeClient.onPermissionRequestgrants it. Holding theCAMERApermission in your app is not enough. Grant it only to ScreenlyyID pages. - Forward the page's events yourself. The hosted page sends
IDV_SESSION_COMPLETEandERRORwithwindow.parent.postMessage, and aWebViewhas no outer page to receive them. Register a JavaScript interface withaddJavascriptInterface, then inject amessagelistener that calls it when the page has loaded.
The pieces to copy#
| What | File in the example |
|---|---|
Ask the back end for a session and for the result (HttpURLConnection, no libraries) | app/src/main/java/com/screenlyyid/democamera/Backend.kt |
| Ask for camera permission before loading the page, send the user to Settings if they chose "Don't ask again" | .../MainActivity.kt |
WebView setup, the camera grant, the event bridge, and only loading ScreenlyyID pages | .../VerificationActivity.kt |
One request for the result after IDV_SESSION_COMPLETE | .../ResultActivity.kt |
| Manifest permissions and the demo-only HTTP allowance for the local back end | app/src/main/AndroidManifest.xml, app/src/main/res/xml/network_security_config.xml |
| The server routes | backend/server.mjs |
Run it#
- Create a
test_API key in the dashboard under Integrations. - Start the back end:
cd backend && SCREENLYYID_API_KEY=test_... node server.mjs. - In the emulator, the app reaches the back end at
http://10.0.2.2:3000(the default). On a real phone, runadb reverse tcp:3000 tcp:3000and setDemoConfig.BACKEND_URLtohttp://localhost:3000. - Run the app from Android Studio, or
./gradlew installDebug.
The network_security_config.xml allows plain HTTP to those two local addresses for the demo only. A real back end uses HTTPS: remove the file and the manifest line that refers to it.