Truv Android SDK
Integrate Truv Bridge into your Android app.
Overview
- Installation — Gradle setup
- Bridge — embed Truv Bridge and handle events
- Order — embed a Truv Order and handle events
See also:
- Package on Maven Central — SDK on Maven Central
- Demo app on GitHub — runnable sample app where you can try Bridge and Order with your own keys and explore the integration code
Installation
Add the Truv SDK to your module's build.gradle:
dependencies {
implementation "com.truv.sdk:android_sdk:LATEST_VERSION"
}Make sure mavenCentral() is included in your project's repository configuration.
Add the INTERNET permission to your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />Bridge
Use TruvBridgeView to embed Truv Bridge into your layout as a full-screen verification flow.
Adding to a layout
In XML:
<com.truv.webview.TruvBridgeView
android:id="@+id/bridgeView"
android:layout_width="match_parent"
android:layout_height="match_parent" />Or create it programmatically:
val bridgeView = TruvBridgeView(context)Initializing and loading
import com.truv.models.TruvEventPayload
import com.truv.models.TruvSuccessPayload
import com.truv.webview.TruvBridgeView
import com.truv.webview.TruvEventsListener
class MyFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val bridgeView = view.findViewById<TruvBridgeView>(R.id.bridgeView)
bridgeView.addEventListener(object : TruvEventsListener {
override fun onLoad() {
// Bridge finished loading
}
override fun onClose() {
// User closed the Bridge
}
override fun onSuccess(payload: TruvSuccessPayload) {
// Called when the Bridge closes after a successful task.
// payload.publicToken — use this to retrieve data server-side.
// payload.metadata.taskId — the task identifier.
}
override fun onEvent(event: TruvEventPayload) {
// Lifecycle event. For the full list of event types and
// their payloads, see:
// https://docs.truv.com/docs/event-reference-for-truv-bridge#onevent-types
// Field names may slightly differ — check the exported Kotlin types.
}
})
bridgeView.loadBridgeTokenUrl(bridgeToken)
}
}Order
Use TruvOrderView to embed an Order — a customizable verification workflow that supports multiple data sources and product types.
Adding to a layout
In XML:
<com.truv.webview.TruvOrderView
android:id="@+id/orderView"
android:layout_width="match_parent"
android:layout_height="match_parent" />Or create it programmatically:
val orderView = TruvOrderView(context)Initializing and loading
import com.truv.models.TruvEventPayload
import com.truv.models.TruvOrderEvent
import com.truv.webview.TruvOrderEventsListener
import com.truv.webview.TruvOrderView
class MyFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val orderView = view.findViewById<TruvOrderView>(R.id.orderView)
orderView.addEventListener(object : TruvOrderEventsListener {
override fun onOrderEvent(event: TruvOrderEvent) {
when (event) {
is TruvOrderEvent.Load -> {
// Order page finished loading
}
is TruvOrderEvent.Close -> {
// User closed the Order
}
is TruvOrderEvent.Success -> {
// A task within the Order completed successfully.
// The Order is still open at this point — it may show
// a success screen or a self-certification screen
// depending on the configuration.
}
is TruvOrderEvent.Completed -> {
// The entire Order is complete (all tasks finished)
}
}
}
override fun onBridgeEvent(event: TruvEventPayload) {
// Fired when the user interacts with the Bridge for a
// sub-order (task) within the Order.
// Equivalent to TruvEventsListener.onEvent().
// See: https://docs.truv.com/docs/event-reference-for-truv-bridge#onevent-types
}
})
orderView.loadOrderUrl(orderToken)
}
}Updated 5 days ago