# Rewarded

## Integration

Just as interstitials, rewarded ads can only be integrated with code. Below we show a simple example to understand how it works:

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

```kotlin
class MainActivity : Activity() {

    private var interstitialAd: InterstitialAd? = null
    
    override fun onCreate(savedInstanceState: Bundle?) {
        ...
        interstitialAd = InterstitialAd(this, "<Wortise Ad Unit ID>").also {
	        it.loadAd()
        }
    }
    
    override fun onDestroy() {
        ...
        interstitialAd?.destroy()
    }
    
    fun showInterstitial() {
        if (interstitialAd?.isAvailable == true) {
            interstitialAd?.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, "Wortise Ad Unit ID");
        mRewarded.loadAd();
    }
    
    @Override
    public void onDestroy() {
        ...
        mRewarded.destroy();
    }
    
    public void showInterstitial() {
        if (mRewarded.isAvailable()) {
            mRewarded.showAd(this);
        }
    }
}
```

{% endtab %}
{% endtabs %}

## **Listener configuration**

Like occurs with other formats, a listener can be set to receive the events that happen during the rewarded lifecycle. For this, it is needed to implement the `RewardedAd.Listener` interface just as shown in the example below:

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

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

    override fun onRewardedClicked(ad: RewardedAd) {
        // Invoked when the ad has been clicked
    }

    override fun onRewardedCompleted(ad: RewardedAd, reward: Reward) {
        // Invoked when the ad has been completed
    }
        
    override fun onRewardedDismissed(ad: RewardedAd) {
        // Invoked when the ad has been dismissed
    }
    
    override fun onRewardedFailedToLoad(ad: RewardedAd, error: AdError) {
        // Invoked when the ad could not be loaded
        // (because of an error or no fill)
    }

    override fun onRewardedFailedToShow(ad: RewardedAd, error: AdError) {
        // Invoked when the ad could not be shown
    }
    
    override fun onRewardedImpression(ad: RewardedAd) {
        // Invoked when the ad has generated an impression
    }    
    
    override fun onRewardedLoaded(ad: RewardedAd) {
        // Invoked when the ad has been loaded
    }
    
    override fun onRewardedRevenuePaid(ad: RewardedAd,
                                       data: RevenueData) {
        // Invoked when the ad has generated revenue
    }
    
    override fun onRewardedShown(ad: RewardedAd) {
        // Invoked when the ad has been shown
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
mRewarded.setListener(new RewardedAd.Listener() {
    @Override
    public void onRewardedClicked(@NonNull RewardedAd ad) {
        // Invoked when the ad has been clicked
    }
    
    @Override
    public void onRewardedCompleted(@NonNull RewardedAd ad,
                                    @NonNull Reward reward) {
        // Invoked when the ad has been completed
    }
    
    @Override
    public void onRewardedDismissed(@NonNull RewardedAd ad) {
        // Invoked when the ad has been dismissed
    }
    
    @Override
    public void onRewardedFailedToLoad(@NonNull RewardedAd ad,
                                       @NonNull AdError error) {
        // Invoked when the ad could not be loaded
        // (because of an error or no fill)
    }

    @Override
    public void onRewardedFailedToShow(@NonNull RewardedAd ad,
                                       @NonNull AdError error) {
        // Invoked when the ad could not be shown
    }
    
    @Override
    public void onRewardedImpression(@NonNull RewardedAd ad) {
        // Invoked when the ad has generated an impression
    }
    
    @Override
    public void onRewardedLoaded(@NonNull RewardedAd ad) {
        // Invoked when the ad has been loaded
    }
    
    @Override
    public void onRewardedRevenuePaid(@NonNull RewardedAd ad,
                                      @NonNull RevenueData data) {
        // Invoked when the ad has generated revenue
    }
    
    @Override
    public void onRewardedShown(@NonNull RewardedAd ad) {
        // Invoked when the ad has been shown
    }
});
```

{% 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/en/android-sdk/sdk-integration/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.
