Android SDK (Kotlin)

Native Kotlin SDK fuer Android API 26+ mit Jetpack Compose Unterstuetzung.

Systemvoraussetzungen

Kotlin Version1.9+
Min SDKAPI 26 (Android 8.0)
Compile SDK34+

Installation

build.gradle.kts (Module)
dependencies {
    implementation("com.breakpilot:consent-sdk:1.0.0")

    // Fuer Jetpack Compose
    implementation("com.breakpilot:consent-sdk-compose:1.0.0")
}

Grundlegende Einrichtung

MyApplication.kt
import android.app.Application
import com.breakpilot.consent.ConsentManager

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        // Consent Manager konfigurieren
        ConsentManager.configure(
            context = this,
            config = ConsentConfig(
                apiEndpoint = "https://api.example.com/consent",
                siteId = "my-android-app"
            )
        )

        // Initialisieren
        lifecycleScope.launch {
            ConsentManager.initialize()
        }
    }
}

Jetpack Compose Integration

MainActivity.kt
import androidx.compose.runtime.*
import com.breakpilot.consent.compose.*

@Composable
fun MainScreen() {
    val consent = rememberConsentState()

    Column {
        // Consent-abhaengige UI
        if (consent.hasConsent(ConsentCategory.ANALYTICS)) {
            AnalyticsView()
        }

        // Buttons
        Button(onClick = { consent.acceptAll() }) {
            Text("Alle akzeptieren")
        }

        Button(onClick = { consent.rejectAll() }) {
            Text("Alle ablehnen")
        }
    }

    // Consent Banner (automatisch angezeigt wenn noetig)
    ConsentBanner()
}

// ConsentGate Composable
@Composable
fun ProtectedContent() {
    ConsentGate(
        category = ConsentCategory.MARKETING,
        fallback = {
            Text("Marketing-Zustimmung erforderlich")
        }
    ) {
        MarketingContent()
    }
}

View-basierte Integration

MainActivity.kt
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.breakpilot.consent.ConsentManager
import kotlinx.coroutines.launch
import kotlinx.coroutines.flow.collect

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Auf Consent-Aenderungen reagieren
        lifecycleScope.launch {
            ConsentManager.consentFlow.collect { state ->
                updateUI(state)
            }
        }

        // Banner anzeigen wenn noetig
        if (ConsentManager.needsConsent()) {
            ConsentManager.showBanner(this)
        }
    }

    private fun updateUI(state: ConsentState?) {
        if (state?.hasConsent(ConsentCategory.ANALYTICS) == true) {
            loadAnalytics()
        }
    }

    fun onAcceptAllClick(view: View) {
        lifecycleScope.launch {
            ConsentManager.acceptAll()
        }
    }
}

API Referenz

MethodeBeschreibung
configure()SDK konfigurieren
initialize()SDK initialisieren (suspend)
hasConsent()Consent fuer Kategorie pruefen
consentFlowFlow fuer reaktive Updates
acceptAll()Alle akzeptieren (suspend)
rejectAll()Alle ablehnen (suspend)
setConsent()Kategorien setzen (suspend)
showBanner()Banner als DialogFragment