Skip to content

Android SDK (Kotlin)

Deliver sponsored push notifications in your Android app. The SDK handles device registration, notification display, click tracking, and display pixel firing — with the ad source fully concealed.

Prerequisites

  • Android minSdk 23 (Android 6.0+)
  • Firebase project with google-services.json in your app module

Install

Add the dependency to your app's build.gradle.kts:

kotlin
dependencies {
    implementation("ai.dlserve:dlserve-android:0.1.0")
}

Initialize

Call init once from Application.onCreate():

kotlin
class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        Dlserve.init(this, appId = "your-app-id")
    }
}

The SDK fetches its configuration and registers the device in the background — it never blocks the main thread.

Wire up FCM

Delegate to the SDK from your existing service:

kotlin
class MyMessagingService : FirebaseMessagingService() {
    override fun onMessageReceived(msg: RemoteMessage) {
        if (Dlserve.handleMessageIfDlserve(this, msg)) return
        // Your own message handling.
    }

    override fun onNewToken(token: String) {
        Dlserve.onNewToken(token)
    }
}

handleMessageIfDlserve returns true and renders the ad notification when the message is from dlserve; false otherwise.

Option B — no existing messaging service

Enable the bundled service in your AndroidManifest.xml:

xml
<service
    android:name="ai.dlserve.sdk.DlserveMessagingService"
    android:enabled="true"
    tools:replace="android:enabled" />

Notification permission

On Android 13+, request the POST_NOTIFICATIONS runtime permission:

kotlin
if (Dlserve.needsNotificationPermission(context)) {
    // Launch your permission request.
}

User identity & tags

kotlin
Dlserve.login("user-123")
Dlserve.logout()

Dlserve.setTags(mapOf(
    "plan" to "premium",
    "trial" to null,   // null deletes the key
))

API reference

MethodDescription
Dlserve.init(context, appId)Initialize the SDK. Call once.
Dlserve.login(externalId)Associate a user ID (max 256 chars).
Dlserve.logout()Clear user association.
Dlserve.setTags(Map<String, String?>)Set tags; null value deletes. Max 20 tags.
Dlserve.onNewToken(token)Forward FCM token rotations.
Dlserve.handleMessageIfDlserve(context, msg)Route FCM message; true = handled.
Dlserve.needsNotificationPermission(context)Check if POST_NOTIFICATIONS needed.