Cartesiandocs

Android SDK

Initialize

Create the Cartesian client once, when your Application starts.

Call Cartesian.initialize in Application.onCreate. It creates the single CartesianClient and stores your default CartesianOptions.

App.kt
class App : Application() {
    override fun onCreate() {
        super.onCreate()
        Cartesian.initialize(
            context = this,
            config = CartesianConfig.builder(Vertical.Grocery, BuildConfig.CARTESIAN_URL)
                .userAgent("FreshMart/4.2")
                .licenseKey(BuildConfig.CARTESIAN_LICENSE)
                .build(),
            options = CartesianOptions.Builder()
                .title("FreshMart Assistant")
                .starters(listOf("Plan 3 vegetarian dinners", "Weekly breakfast staples under $40"))
                .build(),
        )
        Cartesian.listener = FreshMartCartesianListener(this)
    }
}

CartesianConfig

verticalVerticalrequired

Vertical.Grocery or Vertical.Apparel. This selects the product vocabulary, the copy and the auth transport. Grocery uses a session cookie; Apparel uses a bearer WebSocket subprotocol.

baseUrlStringrequired

The root URL of your Cartesian backend, without a trailing /api. The SDK calls <baseUrl>/api/... and opens the socket at <baseUrl>/ws.

okHttpClientOkHttpClient

Use your own client to share its connection pool, interceptors, certificate pinning or proxy settings.

userAgentString

Added after cartesian-android/<version> in the User-Agent header.

loggerCartesianLogger

A fun interface that receives diagnostic lines. Leave it unset in release builds.

licenseKeyString

Your CogitX licence. A white-label licence hides the attribution. See White-label.

Calling it again

initialize is idempotent. Calling it again with the same vertical and baseUrl keeps the existing client, with its session and socket, and only updates the options. If either value changes, the old client is closed and a new one is created. This is useful for switching between staging and production in a debug menu.

Keep the backend URL and licence key in BuildConfig fields that you fill from your CI secrets, not hard-coded in source.

Accessing the client

val client: CartesianClient = Cartesian.client      // throws if initialize wasn't called
if (Cartesian.isInitialized) { /* … */ }
kotlin