> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hakumedia.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Android

> Integración del SDK de Haku en una app Android.

| Requisito       | Versión                         |
| --------------- | ------------------------------- |
| Android         | API 24 (Android 7.0) o superior |
| Kotlin          | 1.9 o superior                  |
| Jetpack Compose | Opcional                        |

## Instalación

Se instala con Gradle. El acceso al paquete se entrega al comenzar la integración.

## Configuración

Una vez, en `Application.onCreate()`:

```kotlin theme={"dark"}
import ai.hakumedia.sdk.core.Haku
import ai.hakumedia.sdk.core.HakuOptions
import ai.hakumedia.sdk.core.HakuLogLevel

class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        Haku.initialize(
            context = this,
            accountId = 182804,
            options = HakuOptions(
                testMode = false,
                logLevel = HakuLogLevel.DEBUG
            )
        )
    }
}
```

## Banner

<CodeGroup>
  ```kotlin Compose theme={"dark"}
  @Composable
  fun MyScreen() {
      HakuBanner(
          request = AdRequest(zoneId = 12345),
          modifier = Modifier.fillMaxWidth().height(250.dp),
          onEvent = { event ->
              when (event) {
                  is BannerAdEvent.Loaded -> Log.d("Ad", "Cargado")
                  is BannerAdEvent.Failed -> Log.e("Ad", "Error: ${event.error.message}")
                  is BannerAdEvent.Impression -> Log.d("Ad", "Impresión visible")
                  is BannerAdEvent.Click -> Log.d("Ad", "Clic")
              }
          }
      )
  }
  ```

  ```kotlin XML theme={"dark"}
  class MainActivity : AppCompatActivity() {
      private lateinit var bannerView: HakuBannerView

      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)

          bannerView = HakuBannerView(this)
          bannerView.listener = object : HakuBannerView.Listener {
              override fun onAdLoaded(view: HakuBannerView, response: AdResponse) {}
              override fun onAdFailed(view: HakuBannerView, error: HakuError) {}
              override fun onImpressionRecorded(view: HakuBannerView) {}
              override fun onClickRecorded(view: HakuBannerView) {}
          }

          findViewById<FrameLayout>(R.id.ad_container).addView(bannerView)
          bannerView.load(AdRequest(zoneId = 12345))
      }
  }
  ```
</CodeGroup>

## Interstitial

```kotlin theme={"dark"}
lifecycleScope.launch {
    interstitialAd = HakuInterstitialAd.load(
        context = this@GameActivity,
        request = AdRequest(zoneId = 67890)
    )
}

interstitialAd?.takeIf { it.isReady }?.show(this)
```

## Nativo

```kotlin theme={"dark"}
val nativeAd = HakuNativeAd.load(request = AdRequest(zoneId = 11111))
nativeAd.onImpression = { Log.d("Ad", "Impresión") }
nativeAd.onClick = { Log.d("Ad", "Clic") }
nativeAd.present(adContainer)
```

## Video

```kotlin theme={"dark"}
HakuVASTPlayer(
    zoneId = 99999,
    modifier = Modifier.fillMaxWidth().aspectRatio(16f / 9f),
    onEvent = { event ->
        when (event) {
            is VASTPlayerEvent.Started -> Log.d("Ad", "Reproduciendo")
            is VASTPlayerEvent.Quartile -> Log.d("Ad", "Cuartil: ${event.quartile}")
            is VASTPlayerEvent.Completed -> Log.d("Ad", "Fin")
            is VASTPlayerEvent.Skipped -> Log.d("Ad", "Saltado")
            else -> {}
        }
    }
)
```

## Opciones del pedido

```kotlin theme={"dark"}
val request = AdRequest.Builder(zoneId = 12345)
    .keywords(listOf("deportes", "running"))
    .size(width = 300, height = 250)
    .dataKeyTargeting(mapOf("categoria" to "electro", "tipo_pagina" to "producto"))
    .referrer("https://miapp.com/articulo/123")
    .uniqueDelivery(pageId = 1, place = 0)
    .build()
```

## ProGuard y R8

```
-keep class ai.hakumedia.sdk.** { *; }
```
