Android SDK

The zerohash Android SDK is a Kotlin library that presents the zerohash flows from your app. Read Mobile SDKs first for the shared concepts, in particular the event model.

Repository: github.com/zerohash-ext/zerohash-android

Requirements

Android5.0+ (API 21)
Kotlin1.9+
Gradle8.2+
JDK17
Packagecom.zerohash.sdk
DistributionMaven Central

Installation

The SDK is published to Maven Central as com.zerohash:zerohash-android. A standard Android project already resolves Maven Central, so usually there is nothing to add to settings.gradle.kts. If your repositories block does not list it yet:

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
    }
}

Then add the dependency:

// app/build.gradle.kts
dependencies {
    implementation("com.zerohash:zerohash-android:<version>")
}

Or with the Groovy DSL:

dependencies {
    implementation 'com.zerohash:zerohash-android:<version>'
}

For <version>, use the current release shown on Maven Central. Pin an exact version and take minor and patch upgrades deliberately; the SDK follows semantic versioning, so any release within the same major is a drop-in replacement.

Integration

Every flow follows the same two steps: configure a session, then present it.

import android.app.Activity
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.zerohash.sdk.Environment
import com.zerohash.sdk.GenericEvent
import com.zerohash.sdk.Theme
import com.zerohash.sdk.ZerohashError
import com.zerohash.sdk.ZerohashSDK
import com.zerohash.sdk.fund.FundCallbacks
import com.zerohash.sdk.fund.FundCompletedEvent
import com.zerohash.sdk.fund.ZerohashFundSession

class MainActivity : AppCompatActivity() {

    private var fundSession: ZerohashFundSession? = null

    private fun openFund(jwt: String) {
        fundSession = ZerohashSDK.configureFund(
            jwt = jwt,
            environment = Environment.PRODUCTION,
            theme = Theme.SYSTEM,
            callbacks = object : FundCallbacks {
                override fun onClose() {
                    fundSession = null
                }

                override fun onCompleted(event: FundCompletedEvent) {
                    // Deposit succeeded.
                }

                override fun onFailed(event: FundCompletedEvent) {
                    // Terminal failed deposit. Not an error — show the reason.
                }

                override fun onError(error: ZerohashError) {
                    // SDK or request error.
                }

                override fun onEvent(event: GenericEvent) {
                    // Optional analytics hook.
                }
            }
        )
        fundSession?.present(this)
    }
}

The other flows are identical in shape:

ZerohashSDK.configureCryptoWithdrawals(jwt = jwt, callbacks = /* CryptoWithdrawalsCallbacks */)
ZerohashSDK.configureFundWithdrawals(jwt = jwt, callbacks = /* FundWithdrawalsCallbacks */)

environment, theme and allowList all have defaults, so a minimal call is configureFund(jwt = jwt, callbacks = ...).

Holding the session

Keep a reference to the returned session for as long as the flow is on screen, as in the example above. Clear it in onClose so the next flow starts fresh.

Dismissing programmatically

fundSession?.cancel()

This closes the flow the same way the user closing it would.

Configuration

Environment

Environment.SANDBOX     // integration and testing
Environment.PRODUCTION  // real activity (default)

Theme

Theme.LIGHT
Theme.DARK
Theme.SYSTEM  // follows the device setting (default)

Host allow-list

Each configure function takes an optional allowList that restricts which hosts the embedded WebView may navigate to or load resources from. The default, ZerohashAllowList.DEFAULT, already covers every host the flows need. Override it only if your security review requires a narrower list, and be aware that removing a host the flow depends on will break it.

ZerohashSDK.configureFund(
    jwt = jwt,
    allowList = ZerohashAllowList(listOf("your.host")),
    callbacks = /* ... */
)

Callbacks

Callback interfaces are per flow, and all extend a shared AppCallbacks.

HandlerFires whenRequired
onCompletedThe transaction completed successfullyYes
onCloseThe user closed the flow, or you called cancel()Yes
onErrorAn SDK or request error occurredYes
onEventA low-level event was forwarded from the flowYes
onLoadedThe flow finished loading and is showing its first screenNo
onFailedThe transaction reached a terminal failed stateNo
onDepositStatus update for a deposit funded from an external source. Fund only, and not terminalNo

See the event model for more details.

Full event payload fields and the sealed ZerohashError hierarchy are documented in the README, which is versioned alongside the SDK.


Did this page help you?