Android SDK

Integrate Appflow into your Android app with the Kotlin SDK. Track events, manage subscriptions through Google Play Billing, display paywalls, and connect attribution data with just a few lines of code.

Requirements

PlatformAndroid 7.0+ (API 24)
LanguageKotlin 1.8+
IDEAndroid Studio Hedgehog+

Installation

Add the Appflow SDK and the optional Billing module to your app-level Gradle file. The Billing module enables automatic Google Play transaction tracking.

Gradle Dependencies

build.gradle.kts · kotlin
// build.gradle.kts (app)
dependencies {
    implementation("ai.appflow:sdk:2.0.0")
    implementation("ai.appflow:sdk-billing:2.0.0") // Google Play Billing
}

Maven Repository

Add the Appflow Maven repository to your project-level settings.gradle.kts:

settings.gradle.kts · kotlin
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url = uri("https://maven.appflow.ai/releases") }
    }
}

Configuration

Initialize the SDK in your custom Application class. This ensures the SDK is ready before any Activity launches. Your appId and client key (ck_ prefix) are available in the Appflow dashboard under Settings → API Keys.

MyApplication.kt · kotlin
class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        Appflow.configure(
            context = this,
            appId = "app_xxx",
            apiKey = "ck_xxx",
            options = AppflowOptions(
                environment = Environment.PRODUCTION,
                logLevel = LogLevel.INFO,
                flushInterval = 30,
                flushAt = 20
            )
        )
    }
}

The flushInterval controls how often batched events are sent (in seconds), and flushAt sets the batch size threshold. Remember to register your Application class in AndroidManifest.xml.

Identify Users

Associate a known user with their events. Call identify once the user has signed in or when you have a stable user identifier. All subsequent events will be attributed to this user.

UserAuth.kt · kotlin
Appflow.identify("user_12345", mapOf(
    "email" to "user@example.com",
    "plan" to "premium",
    "signup_date" to "2025-01-15"
))

Track Events

Track custom events to understand user behavior. Events are batched locally and flushed according to your configuration. See the Event Tracking Guide for naming conventions and best practices.

Events.kt · kotlin
// Simple event
Appflow.track("button_tapped")

// Event with properties
Appflow.track("purchase_started", mapOf(
    "product_id" to "pro_monthly",
    "price" to "9.99",
    "currency" to "USD"
))

// Screen views
Appflow.trackScreen("Settings")

Revenue Tracking

The SDK integrates with Google Play Billing to automatically capture subscription and in-app purchase transactions. Enable it in your configuration, or report transactions manually for full control.

Automatic Google Play Billing

AppConfig.kt · kotlin
// Auto-track with Billing integration
Appflow.configure(
    context = this,
    appId = "app_xxx",
    apiKey = "ck_xxx",
    options = AppflowOptions(
        trackGooglePlayBilling = true
    )
)

Manual Revenue Reporting

Revenue.kt · kotlin
// Or manual:
Appflow.trackRevenue(
    productId = "pro_monthly",
    priceCents = 999,
    currency = "USD",
    orderId = "GPA.xxx",
    type = RevenueType.SUBSCRIPTION
)

Paywalls

Powered by the Build Engine. Fetch remotely configured paywall layouts and present them as an Activity. Paywall designs are managed in the Appflow dashboard and delivered over the air without app updates.

Paywall.kt · kotlin
val paywall = Appflow.getPaywall("main_paywall")

val result = AppflowPaywallActivity.launch(this, paywall)
when (result) {
    is PaywallResult.Purchased -> println("Purchased: ${result.product.id}")
    is PaywallResult.Restored -> println("Restored")
    is PaywallResult.Dismissed -> println("Dismissed")
}

Attribution

Powered by the Acquire Engine. Pass attribution data from your Mobile Measurement Partner (MMP) so Appflow can connect ad spend to downstream revenue and compute ROAS.

Attribution.kt · kotlin
Appflow.setAttribution(
    source = AttributionSource.APPSFLYER,
    data = mapOf(
        "campaign" to "summer_sale",
        "adgroup" to "lookalike_us",
        "network" to "meta"
    )
)

Push Notifications

Integrate with Firebase Cloud Messaging to register device tokens and let Appflow handle delivery tracking. Extend FirebaseMessagingService and forward token updates and incoming messages to the SDK.

AppflowMessagingService.kt · kotlin
class AppflowMessagingService : FirebaseMessagingService() {
    override fun onNewToken(token: String) {
        Appflow.registerForPush(token)
    }
    override fun onMessageReceived(message: RemoteMessage) {
        Appflow.handlePushNotification(message.data)
    }
}

ProGuard Rules

If you use code shrinking with R8 or ProGuard, add the following rules to prevent the SDK classes from being removed or obfuscated:

proguard-rules.pro · proguard
-keep class ai.appflow.sdk.** { *; }
-dontwarn ai.appflow.sdk.**