# Rewarded

## Integración

Los anuncios recompensados (rewarded), al igual que los intersticiales, únicamente se pueden integrar a través de código. A continuación se muestra un sencillo ejemplo para entender su funcionamiento:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
class MainActivity : Activity() {

    private var rewardedAd: RewardedAd? = null
    
    override fun onCreate(savedInstanceState: Bundle?) {
        ...
        rewardedAd = RewardedAd(this, "Ad Unit ID de Wortise").also {
	          it.loadAd()
        }
    }
    
    override fun onDestroy() {
        ...
        rewardedAd?.destroy()
    }
    
    fun showInterstitial() {
        if (rewardedAd?.isAvailable == true) {
            rewardedAd?.showAd(this)
        }
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
public class MainActivity extends Activity {

    private RewardedAd mRewarded;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        ...
        mRewarded = new RewardedAd(this, "Ad Unit ID de Wortise");
        mRewarded.loadAd();
    }
    
    @Override
    public void onDestroy() {
        ...
        mRewarded.destroy();
    }
    
    public void showInterstitial() {
        if (mRewardedrstitial.isAvailable()) {
            mRewarded.showAd(this);
        }
    }
}
```

{% endtab %}
{% endtabs %}

## **Configuración del listener**

Como en el resto de formatos, se puede añadir un listener para recibir los diferentes eventos\
que sucedan durante el ciclo de vida del anuncio recompensado. Para ello, es necesario implementar la interfaz `RewardedAd.Listener` como se muestra en el siguiente ejemplo:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
rewardedAd.listener = object : RewardedAd.Listener() {

    override fun onRewardedClicked(ad: RewardedAd) {
        // Invocado cuando el anuncio ha sido clickeado
    }
    
    override fun onRewardedCompleted(ad: RewardedAd, reward: Reward) {
        // Invocado cuando el anuncio ha sido completado
    }
    
    override fun onRewardedDismissed(ad: RewardedAd) {
        // Invocado cuando el anuncio ha sido cerrado
    }
    
    override fun onRewardedFailedToLoad(ad: RewardedAd, error: AdError) {
        // Invocado cuando el anuncio no se ha podido cargar
        // (por error o falta de inventario)
    }
    
    override fun onRewardedFailedToShow(ad: RewardedAd, error: AdError) {
        // Invocado cuando el anuncio no se ha podido mostrar
    }
    
    override fun onRewardedImpression(ad: RewardedAd) {
        // Invocado cuando el anuncio ha generado una impresión
    }

    override fun onRewardedLoaded(ad: RewardedAd) {
        // Invocado cuando el anuncio ha sido cargado
    }
    
    override fun onRewardedRevenuePaid(ad: RewardedAd,
                                       data: Revenuedata) {
        // Invocado cuando el anuncio ha generado un ingreso
    }
    
    override fun onRewardedShown(ad: RewardedAd) {
        // Invocado cuando el anuncio ha sido mostrado
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
mRewarded.setListener(new RewardedAd.Listener() {
    @Override
    public void onRewardedClicked(@NonNull RewardedAd ad) {
        // Invocado cuando el anuncio ha sido clickeado
    }
    
    @Override
    public void onRewardedCompleted(@NonNull RewardedAd ad,
                                    @NonNull Reward reward) {
        // Invocado cuando el anuncio ha sido completado
    }
    
    @Override
    public void onRewardedDismissed(@NonNull RewardedAd ad) {
        // Invocado cuando el anuncio ha sido cerrado
    }
    
    @Override
    public void onRewardedFailedToLoad(@NonNull RewardedAd ad,
                                       @NonNull AdError error) {
        // Invocado cuando el anuncio no se ha podido cargar
        // (por error o falta de inventario)
    }
    
    @Override
    public void onRewardedFailedToShow(@NonNull RewardedAd ad,
                                       @NonNull AdError error) {
        // Invocado cuando el anuncio no se ha podido mostrar
    }
    
    @Override
    public void onRewardedImpression(@NonNull Rewar ad) {
        // Invocado cuando el anuncio ha generado una impresión
    }
    
    @Override
    public void onRewardedLoaded(@NonNull RewardedAd ad) {
        // Invocado cuando el anuncio ha sido cargado
    }
    
    @Override
    public void onRewardedRevenuePaid(@NonNull RewardedAd ad,
                                      @NonNull Revenuedata data) {
        // Invocado cuando el anuncio ha generado un ingreso
    }
    
    @Override
    public void onRewardedShown(@NonNull RewardedAd ad) {
        // Invocado cuando el anuncio ha sido mostrado
    }
});
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wortise.com/android-sdk/integracion-del-sdk/rewarded.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
