Initializing the LucraClient

After setting up your project with the necessary dependencies, you can initialize the LucraClient in your primary activity class, or any context driven class which hosts the Lucra launch points, initialize the Lucra instance in the onCreate function.

For the apiKey, please reach out to your Lucra Representative to obtain these. You will receive an apiKey for Environment.PRODUCTION and another for Environment.SANDBOX, using the wrong apiKey for a given environment will lead to unauthorized access errors.

LucraClient.initialize(
  // Required - provided api key to use for LucraSDK usage. One for SANDBOX and one for PRODUCTION
  apiKey = "YOUR_API_KEY_HERE", 
  // Provide the Environment, **the `apiKey` above must match the environment specified here**.
  environment = Environment.SANDBOX,
  // Provide LucraUiProvider implementation from "com.lucrasports.sdk:sdk-ui:*"
  // This drives the Lucra UI experience, what shows and when it shows
  lucraUiProvider = LucraUi(
    lucraFlowListener = object : LucraFlowListener {

        // Callback for entering Lucra permitted flow launch points.
        // At this point, LucraSDK is asking to display a new destination flow that you can chose to display in a different Fragment or Activity. **Return false to allow LucraSDK to show the next destination within it's own nav graph**
        // NOTE: This is only called after a Flow is initially displayed
      override fun launchNewLucraFlowEntryPoint(entryLucraFlow: LucraUiProvider.LucraFlow): Boolean {
        Log.d("Sample", "launchNewLucraFlowEntryPoint: $entryLucraFlow")
        // Here, the sample is choosing to display a new fragment.
        showLucraDialogFragment(entryLucraFlow)
        return true
      }

      //Callback for exiting all Lucra permitted flow launch points
      // If `launchNewLucraFlowEntryPoint` owned the given Flow, this callback is responsible for dismissing any Dialogs or Fragments which owned it, so it follows the natural progression of Flows displaying for the user.
      override fun onFlowDismissRequested(entryLucraFlow: LucraUiProvider.LucraFlow) {
        Log.d("Sample", "onFlowDismissRequested: $entryLucraFlow")
        supportFragmentManager.findFragmentByTag(entryLucraFlow.toString())?.let {
          Log.d("Sample", "Found $entryLucraFlow as $it")

          if (it is DialogFragment)
            it.dismiss()
          else
            supportFragmentManager.beginTransaction().remove(it).commit()
        } ?: run {
          Log.d("Sample", "onFlowDismissRequested: $entryLucraFlow not found")
        }
      }
    }
  ),
  // Optionally provide Lucra.Logger implementation to track events happening through the experience
  // This gives you insight into errors, non-fatals and analytics tracked throughout the experience.
  customLogger = null,
  // Optionally specify to output logs to Logcat, defaults to false
  outputLogs = true,
  // Optionally add your own color scheme and fonts, from "com.lucrasports.sdk:sdk-ui:*", defaults to the Lucra Defaults
  // See more here [Theming/Appearance](1.2.1_theming.md)
  clientTheme = ClientTheme(
    lightColorStyle = ColorStyle(),
    darkColorStyle = ColorStyle(),
    fontFamily = FontFamily(
      mediumFont = Font("bauziet_norm_medium.otf"),
      normalFont = Font("bauziet_norm_regular.otf"),
      semiBoldFont = Font("bauziet_norm_bold.otf"),
      boldFont = Font("bauziet_norm_extra_bold.otf"),
    )
  )
)

Interacting with the LucraClient asynchronously

Sometimes you need to trigger work (e.g., headless calls) only after the SDK is fully initialized. Use one of the waitForLucraClient helpers before you call into the SDK:

  • Coroutine-friendly (Kotlin):

  • Callback-friendly (Java/Kotlin): waitForLucraClient(onSuccess: Runnable, onFailure: Consumer<Throwable>? = null)

Why this matters: headless calls (see Headless Support) will fail if invoked before initialization completes. Waiting ensures your calls only run once the SDK is ready.

Launching Flowsarrow-up-right will show a loading experience until the SDK is has successfully initialized with the provided apiKey.

After LucraClient is initialized

Now that the LucraClient is initialized, let's display your first Lucra Flow.

Lucra Flowsarrow-up-right

In combination with LucraFlows, our Headless functionality can be leveraged to flush out the user journey.

LucraClient Headless Supportarrow-up-right

This document follows the minimum requirements for the LucraClient to get started. If you're looking for more information around the supported functionality, navigate to one of the links below

Theming/Appearancearrow-up-right Deeplink Supportarrow-up-right Push Notification Supportarrow-up-right Payment Supportarrow-up-right Convert to Credit Supportarrow-up-right Free to Play Supportarrow-up-right LucraEvent Listenerarrow-up-right

Last updated