> For the complete documentation index, see [llms.txt](https://docs.wortise.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wortise.com/android-sdk/integracion-del-sdk/rewarded.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
