Android SDK

Kotlin · Android 8+ · Jetpack Compose

Overview

The Avafli Engagement SDK lets you add daily-entry sweepstakes and prize experiences to your app with a single configuration call. The SDK automatically opens the experience on the first app-open of each day, captures the user, and claims their daily entries — no scheduling or session logic on your side. You customize your logo, prize image, and brand color from the Avafli dashboard; everything else is managed server-side.

Requirements

Android8.0+ (API 26)
Kotlin2.1+
Jetpack ComposeBOM 2024.12.01+
Publisher API KeyContact info@avafli.com

Installation

Gradle (via JitPack)

Add JitPack to your project-level settings.gradle.kts:

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url = uri("https://jitpack.io") }
    }
}

Add the dependency to your app-level build.gradle.kts:

dependencies {
    implementation("com.github.AVAFLI:avafli_android_sdk:v3.2.0")
}

Quick Start

The simplest integration requires just two calls:

MainActivity.kt
import com.avafli.avaflisdk.Avafli
import com.avafli.avaflisdk.AvafliAutoOpen
import com.avafli.avaflisdk.AvafliConfiguration
import com.avafli.avaflisdk.AvafliOptions
import com.avafli.avaflisdk.AvafliUser

val config = AvafliConfiguration(
    context = applicationContext,
    apiKey = "YOUR_API_KEY",  // debug builds: use your avafli_test_ sandbox key
    autoOpen = AvafliAutoOpen.ALWAYS,  // or RETURNING_USERS_ONLY / NEVER
    user = AvafliUser(
        id = "user_123",              // only id is required — pass whatever identity you have
        firstName = "Jane",
        lastName = "Doe",
        email = "jane@example.com"    // include it when you have it — pre-fills & locks the capture form
    ),
    // Nobody signed in? use user = AvafliUser.GUEST
    options = AvafliOptions(
        debugLogging = false,         // true while integrating
        enablePushReminders = true    // streak reminders via YOUR Firebase project
    )
)
Avafli.configure(config)

// Done — auto-opens once a day. To open it yourself: Avafli.present()
// Push reminders: forward your FCM token: Avafli.onNewToken(token)

By default the experience opens itself on the first app-open of each day — presentation timing, the daily cadence, and dismissal are managed by the SDK. When your app needs to decide the moment, use the controls below.

Controlling when the drawer opens

The default is unchanged: the drawer opens itself once a day on app open. Three controls change that when you need to:

  • autoOpen on the configuration — AvafliAutoOpen.ALWAYS (default), AvafliAutoOpen.RETURNING_USERS_ONLY, or AvafliAutoOpen.NEVER. AvafliAutoOpen.RETURNING_USERS_ONLY keeps the drawer out of a first-time user's onboarding: it skips the auto-open on the launch where the device is first registered, then auto-opens normally on every later launch. AvafliAutoOpen.NEVER means the SDK never auto-opens and you call Avafli.present(activity).
  • Avafli.present(activity) — open the drawer from a button, a screen, or an onboarding-complete handler. It ignores the once-a-day rule and the impression cap, waits for registration if it is still in flight, and no-ops if the drawer is already open or the user has opted out. Pass the Activity to present from; the optional callback receives the DailyEntryGrant once today's entry is claimed.
  • Avafli.holdAutoOpen() / Avafli.releaseAutoOpen() — for boot flows. Call Avafli.holdAutoOpen() before configuring to defer the daily auto-open (nothing is burned — no once-a-day mark, no impression), and Avafli.releaseAutoOpen() once your main screen is ready; it re-runs the eligibility check immediately. Avafli.present(activity) still works while held.
val config = AvafliConfiguration(
    context = applicationContext,
    apiKey = "YOUR_API_KEY",
    user = AvafliUser(id = "user_123"),
    autoOpen = AvafliAutoOpen.NEVER  // ALWAYS (default) | RETURNING_USERS_ONLY | NEVER
)
Avafli.configure(config)

// Later — e.g. from your onboarding-complete handler
fun onOnboardingComplete() {
    Avafli.present(this) { result ->   // this = the current Activity
        // Result.success(grant) once today's entry is claimed
    }
}

Registration and analytics (DAU/MAU) run on configure regardless of mode.

Push Notifications

Drive re-engagement with daily reminders. Forward your FCM token to the SDK:

class MyFirebaseMessagingService : FirebaseMessagingService() {
    override fun onNewToken(token: String) {
        super.onNewToken(token)
        Avafli.onNewToken(token)
    }
}

Upload your FCM service account key via the Avafli Dashboard to enable push notifications.

Account deletion in your app

If your app has its own delete-account flow, call optOut() from it so the user's Avafli data is erased along with their account. Users can also delete their data themselves at any time from the Privacy Policy screen inside the experience — no integration required.

// From your delete-account flow (optOut is a suspend function)
lifecycleScope.launch { Avafli.optOut() }

Testing? Your dashboard also shows a avafli_test_ sandbox key. Use it in debug builds: identical behavior against the production backend, but users and entries land in an isolated sandbox — your testers can never enter your real giveaway.

SDK Features

Device registration & token management
Escalating streak ladder with milestone accelerators
Daily or visit-based streak modes
Winner announcements & celebrations
Auto-open on first daily app-open
Email & age gate capture
Geo-fence support
Certificate pinning
Built-in analytics
FCM push notification support
Anti-spam & rate limiting
Right-to-be-forgotten (GDPR)
Custom logo, prize image & brand color

Full API Reference & Code Examples

View the complete documentation on GitHub including API reference, code examples, and advanced configuration.