Skip to content

Android (Kotlin)

The Android SDK renders surveys with Jetpack Compose. It mirrors the iOS SDK’s model (initialise once, attach a host, present surveys by identifier), with a few platform-specific names noted below.

The SDK is published to Maven Central. Add it to your module’s build.gradle.kts:

dependencies {
implementation("eu.whiskrkit:whiskrkit-android:0.3.0")
}

Make sure mavenCentral() is in your repositories and your app’s minSdk is 24 or higher.

The object WhiskrKit is the entry point for all SDK interactions. All methods are synchronous, return Unit, and should be called on the main thread.


initialize(context, apiKey, withMockedSurveys)

Section titled “initialize(context, apiKey, withMockedSurveys)”

Initialises the SDK. Call once from Application.onCreate() on the main thread, before any other WhiskrKit method. Only the application context is retained.

import eu.whiskrkit.WhiskrKit
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
WhiskrKit.initialize(
context = this,
apiKey = "wk_live_your_api_key",
withMockedSurveys = false,
)
}
}
ParameterTypeDescription
contextContextApplication context; only the application context is retained
apiKeyStringYour WhiskrKit API key from the dashboard: a test key for debug builds, a live key for releases (more)
withMockedSurveysBooleanUse local mock data instead of hitting the API. Defaults to false

When withMockedSurveys is true, the SDK bypasses all network calls, which is useful during development and UI testing.


Imperatively presents a survey, bypassing eligibility checks.

WhiskrKit.present(surveyId = "nps-survey")
ParameterTypeDescription
surveyIdStringThe identifier of the survey to present

Requires a WhiskrKitHost in the composition. Unlike iOS, a present call made before a host exists is buffered and delivered to the first host that appears.


Checks eligibility and presents a survey if the user qualifies. The timing is yours; the targeting decision stays with the backend.

WhiskrKit.checkAndPresent(surveyId = "settings-feedback")
ParameterTypeDescription
surveyIdStringThe identifier of the survey to evaluate and potentially present

Requires a WhiskrKitHost in the composition. If eligibility fails, this is a no-op.


Called each time the user submits a survey, for example to log it in your own analytics or to move on in a flow. Available from 0.2.0.

WhiskrKit.setOnSurveyCompletedListener { completion ->
analytics.log("survey_completed", completion.surveyId)
}
PropertyTypeDescription
surveyIdStringThe identifier of the submitted survey
answersList<SurveyCompletion.Answer>The submitted answers, ordered by question id. Each has a questionId, a questionType (SCALE_RATING, SYMBOL_RATING, THUMBS_RATING, TEXTUAL_SURVEY or MULTIPLE_CHOICE) and a value (Value.Score, Value.Thumbs, Value.Text or Value.Choices). Unanswered questions are left out.

Called on the main thread as soon as the user submits, whether or not the response reaches the server (a failed submission is queued and retried). It is not called when a survey is dismissed without submitting, and it is also called with mocked surveys. Pass null to remove the listener.

Attach context about the current user or session to every survey response submitted afterwards, such as the user’s plan or an experiment variant. They’re stored with each response; see Attributes for what to send and what not. Attributes are held in memory only, so set them again at launch. Safe to call from any thread. Available from 0.2.0.

WhiskrKit.setAttribute("plan", "pro")
WhiskrKit.setAttribute("sessions", 3)
WhiskrKit.setAttributes(mapOf("tier" to "gold", "beta" to true)) // merges
WhiskrKit.removeAttribute("tier")
WhiskrKit.clearAttributes()

Values are strings, numbers or booleans. Limits: 20 attributes, keys of 1 to 64 characters, text values up to 256 characters and 2 KB in total; the SDK trims anything beyond.

WhiskrKit’s own strings (the submit button, “required” and the accessibility labels) follow the language the survey was served in, so they match your question text. Without a language from the server they follow the app’s language. Built-in strings are translated into English, Dutch, German, French, Spanish, Italian, Portuguese, Japanese, Korean and Simplified Chinese. Available from 0.2.0.

Rating questions show the colours, end labels and display style of their metric (NPS, CSAT, CES or custom). There is nothing to configure in your app; see Rating metrics. Available from 0.3.0.

On the Free plan, toasts and sheets show a small “Powered by WhiskrKit” line below the submit button. The server decides when it appears; there is nothing to configure in your app. It adapts to your theme and dark mode, and is hidden on paid plans.


Registers the attachment point for surveys and hosts all presentation (sheet, full-screen, banner). Wrap your app’s root content in it, once.

import eu.whiskrkit.ui.WhiskrKitHost
import eu.whiskrkit.theme.WhiskrKitTheme
setContent {
MyAppTheme {
WhiskrKitHost(theme = WhiskrKitTheme(/* ... */)) {
AppContent()
}
}
}
ParameterTypeDescription
modifierModifierStandard Compose modifier. Defaults to Modifier
themeWhiskrKitTheme?Optional theme applied to all survey UI. Defaults to null
content@Composable () -> UnitYour app content

Without a host in the composition, present / checkAndPresent render nothing (buffered at most).


Automatically evaluates eligibility and presents a survey when the composable enters the composition.

import eu.whiskrkit.ui.WhiskrKitSurvey
@Composable
fun HomeScreen() {
WhiskrKitSurvey(identifier = "nps-survey")
}
ParameterTypeDescription
identifierStringThe survey identifier from the dashboard

Unlike iOS (which has setTheme), Android takes the theme as a parameter on WhiskrKitHost:

WhiskrKitHost(theme = WhiskrKitTheme(/* ... */)) { AppContent() }

WhiskrKitTheme is composed of Compose types (Color, TextStyle, Dp) with nested container, button, text, and selection themes. WhiskrKit supports dark mode and Dynamic Type natively; supply adaptive colours for best results.

From 0.3.0, a banner’s own title and description can have their own text styles, separate from the question title. Left out, they use the headline and subheadline:

WhiskrKitTheme(
container = WhiskrKitTheme.ContainerTheme(
banner = WhiskrKitTheme.BannerTheme(
title = WhiskrKitTheme.TextTheme(
textStyle = TextStyle(fontSize = 13.sp, fontWeight = FontWeight.SemiBold),
),
),
),
)
  • Toast is called banner. Android’s toast-style surveys use the name “banner” throughout the theme API (ContainerTheme.banner); iOS calls the same style “toast”.
  • No placement API. SheetPlacement / ToastPlacement are iOS-only. Android has no placement concept.
  • Theme is set via the host, not a setTheme method.
  • Buffered triggers. A present fired before the host exists is buffered on Android; on iOS it is a no-op.
RequirementMinimum
minSdk24
UI toolkitJetpack Compose 1.10 or later