-
Notifications
You must be signed in to change notification settings - Fork 0
JavaInterop
The Convert Android SDK is Kotlin-first but designed for clean use from Java. Static factories, default-argument overloads, and SAM-convertible callbacks mean Java callers need no Kotlin glue. This page shows the Java forms of the common calls; the Kotlin forms are in Code Examples.
ConvertSDK.builder(context) is a @JvmStatic factory, callable directly from Java. Builder setters chain:
import com.convert.sdk.android.ConvertSDK;
import com.convert.sdk.core.model.LogLevel;
ConvertSDK sdk = ConvertSDK.builder(getApplicationContext())
.sdkKey("YOUR_SDK_KEY")
.logLevel(LogLevel.INFO)
.build();onReady takes a Runnable, so a Java lambda works verbatim:
sdk.onReady(() -> {
ConvertContext ctx = sdk.createContext();
Variation variation = ctx.runExperience("homepage-redesign");
applyVariation(variation);
});runExperience, runExperiences, and trackConversion carry @JvmOverloads, so the default-argument arities are generated for Java — you do not pass the optional parameters unless you need them:
// arity-1: enableTracking defaults to true
Variation v = ctx.runExperience("homepage-redesign");
// arity-2: suppress the tracking event
Variation quiet = ctx.runExperience("homepage-redesign", false);
// all experiences
java.util.List<Variation> all = ctx.runExperiences();
Feature feature = ctx.runFeature("checkout-v2");
if (feature != null && feature.getEnabled()) {
enableCheckoutV2();
}The scalar accessors live on the FeatureExtensions static facade (@file:JvmName("FeatureExtensions")). Call them as static methods with the Feature as the first argument:
import com.convert.sdk.android.FeatureExtensions;
String color = FeatureExtensions.getString(feature, "ctaColor");
Integer limit = FeatureExtensions.getInt(feature, "maxItems");
Double price = FeatureExtensions.getDouble(feature, "price");
Boolean experimental = FeatureExtensions.getBoolean(feature, "experimental");Each returns null when the key is absent or the value cannot be coerced. Alternatively, read feature.getVariables().get("key") and decode the JsonElement yourself.
trackConversion has three generated arities — (key), (key, goalData), and (key, goalData, conversionSetting). The goal-key-only form is the common case:
ctx.trackConversion("signup-completed");To attach goal data, build GoalData(GoalDataKey, JsonElement) values. Each value is a kotlinx.serialization.json.JsonElement; build primitives with the JsonPrimitive(...) factory functions from kotlinx.serialization.json, which Java reaches through the generated JsonElementKt facade:
import com.convert.sdk.core.model.GoalData;
import com.convert.sdk.core.model.GoalDataKey;
import kotlinx.serialization.json.JsonElement;
import kotlinx.serialization.json.JsonElementKt;
import java.util.List;
JsonElement amount = JsonElementKt.JsonPrimitive(49.99);
JsonElement txId = JsonElementKt.JsonPrimitive("tx-42");
List<GoalData> data = List.of(
new GoalData(GoalDataKey.AMOUNT, amount),
new GoalData(GoalDataKey.TRANSACTION_ID, txId)
);
ctx.trackConversion("purchase-completed", data);If your codebase is mostly Java, a tiny Kotlin helper that returns a List<GoalData> is often the most readable way to assemble goal data.
EventCallback is a Kotlin fun interface, so Java lambdas SAM-convert to it automatically. on(...) returns a SubscriptionToken:
import com.convert.sdk.android.SubscriptionToken;
import com.convert.sdk.core.event.SystemEvents;
SubscriptionToken token = sdk.on(SystemEvents.BUCKETING, data -> handle(data));
// later
sdk.off(SystemEvents.BUCKETING, token);sdk.setTrackingEnabled(false);
sdk.setTrackingEnabled(true);
boolean enabled = sdk.isTrackingEnabled();| Kotlin | Java |
|---|---|
ConvertSDK.builder(ctx) |
ConvertSDK.builder(ctx) (@JvmStatic) |
sdk.onReady { } |
sdk.onReady(() -> { }) (Runnable) |
ctx.runExperience(key) |
ctx.runExperience(key) (@JvmOverloads) |
feature.enabled |
feature.getEnabled() |
feature.getString("k") |
FeatureExtensions.getString(feature, "k") |
sdk.on(event) { } |
sdk.on(event, data -> { }) (SAM) |
- Code Examples — the Kotlin forms
- Return Types & Models — the types referenced here
Copyrights © 2026 All Rights Reserved by Convert Insights, Inc.
Getting Started
Android SDK
- Quickstart
- Installation
- Initialization
- Configuration
- Return Types & Models
- Code Examples
- Offline Behavior
- Tracking Control
- Google Play Data Safety
- Java Interop
Core Concepts
- Experiences & Variations
- Feature Flags
- Bucketing Algorithm
- Rule Evaluation
- Segments
- Data Management
- Event System
- API Communication
How-To Guides
- Running Experiences
- Running Features
- Tracking Conversions
- Visitor Context
- Persistent DataStore
- Troubleshooting
Contributing