# Rewarded Ads

Rewarded ads are full-screen, video or interactive ads that offer users an in-app reward (like extra lives, in-game currency, or exclusive content) for watching the complete ad.

## Building the Ad Placement (Ad Spot) <a href="#h_01hvkbkvnetmv9cvpvp949vxv9" id="h_01hvkbkvnetmv9cvpvp949vxv9"></a>

Add the required controllers to set up the ad placement:

{% code title="Java" %}

```java
// Spot integration for Rewarded Ads
InneractiveAdSpot mSpot = InneractiveAdSpotManager.get().createSpot();

// Adding the adview controller
InneractiveFullscreenUnitController controller = new InneractiveFullscreenUnitController();

// Adding the Video adview controller
InneractiveFullscreenVideoContentController videoContentController = new InneractiveFullscreenVideoContentController();

controller.addContentController(videoContentController);

mSpot.addUnitController(controller);
```

{% endcode %}

## Adding Listeners <a href="#h_01hvkbkvnepav23dd5m3gmx4n5" id="h_01hvkbkvnepav23dd5m3gmx4n5"></a>

Add listeners for the controller and the spot.

### Adding Event Listener for the Controller <a href="#id-01k7bx3d1jynmta7vvce1286rx" id="id-01k7bx3d1jynmta7vvce1286rx"></a>

The examples below demonstrate how you would add an `EventListener` to receive rewarded ad callbacks:&#x20;

#### Events: <a href="#h_01k83r5g56k6ewhhv14gtmgqbh" id="h_01k83r5g56k6ewhhv14gtmgqbh"></a>

{% code title="Java" %}

```java
controller.setEventsListener(new InneractiveFullscreenAdEventsListener() {
    @Override
    public void onAdImpression(InneractiveAdSpot inneractiveAdSpot) {
    }
    @Override
    public void onAdClicked(InneractiveAdSpot inneractiveAdSpot) {
    }
    @Override
    public void onAdWillOpenExternalApp(InneractiveAdSpot inneractiveAdSpot) {
    }
    @Override
    public void onAdEnteredErrorState(InneractiveAdSpot inneractiveAdSpot, InneractiveUnitController.AdDisplayError adDisplayError) {
    }
    @Override
    public void onAdWillCloseInternalBrowser(InneractiveAdSpot inneractiveAdSpot) {
    }
    @Override
    public void onAdDismissed(InneractiveAdSpot inneractiveAdSpot) {
    }
});
```

{% endcode %}

#### Video Events: <a href="#h_01hvkbkvnewvpga227gdzbmdjr" id="h_01hvkbkvnewvpga227gdzbmdjr"></a>

{% code title="Java" %}

```java
videoContentController.setEventsListener(new VideoContentListener() {
    @Override
    public void onProgress(int totalDurationInMsec, int positionInMsec) {
    }
    @Override
    public void onCompleted() {
    }
    @Override
    public void onPlayerError() {
        /**
         * Note: onPlayerError callback method is deprecated starting from Marketplace v7.3.0,
         and won't be triggered when an error occurs.
         * Note: The SDK handles such errors internally and no further action is required.
         */
    }
});
```

{% endcode %}

#### Rewarded Events:  <a href="#h_01k4w6d3ksbksg89sd3w8kacbx" id="h_01k4w6d3ksbksg89sd3w8kacbx"></a>

You can also use `InneractiveFullScreenAdRewardedListener` to receive Rewarded Ad callbacks.

{% code title="Java" %}

```java
controller.setRewardedListener(new InneractiveFullScreenAdRewardedListener() {
    @Override
    public void onAdRewarded(InneractiveAdSpot inneractiveAdSpot) {
    }
});
```

{% endcode %}

### Adding Request Listener for the Spot <a href="#id-01k7bwyagvyjxhj5dn88rshj9h" id="id-01k7bwyagvyjxhj5dn88rshj9h"></a>

The example below demonstrates how you would use a `RequestListener`:

{% code title="Java" %}

```java
InneractiveAdSpot.RequestListener mSpotListener = new InneractiveAdSpot.RequestListener() 
{
    @Override
//when the ad request sends successfully.
    public void onInneractiveSuccessfulAdRequest(InneractiveAdSpot inneractiveAdSpot) {
    }

    @Override
    public void onInneractiveFailedAdRequest(InneractiveAdSpot inneractiveAdSpot, InneractiveErrorCode inneractiveErrorCode) {
    }
};

mSpot.setRequestListener(mSpotListener);
```

{% endcode %}

## Fetching the Ad <a href="#id-01k7bwsy96q9gxdjhraahnyhs1" id="id-01k7bwsy96q9gxdjhraahnyhs1"></a>

The way in which the ad is fetched depends on the mediation type — Waterfall or SDK Bidding.

### Fetching the Ad for Waterfall <a href="#id-01k7bwsy96yt6t89qr6kgkvkhb" id="id-01k7bwsy96yt6t89qr6kgkvkhb"></a>

Use `InneractiveAdRequest adRequest` to set up the ad placement request:

{% code title="Java" %}

```java
InneractiveAdRequest adRequest = new InneractiveAdRequest("your_rewarded_spot_id");

// When ready to perform the ad request
mSpot.requestAd(adRequest);
```

{% endcode %}

Optionally, you can mute ads including `setMuteVideo(true)`:

{% code title="Java" %}

```java
InneractiveAdManager.setMuteVideo(true);
```

{% endcode %}

### Fetching the Ad for SDK Bidding <a href="#id-01k7bwvmvdmskc1pg3235dkw19" id="id-01k7bwvmvdmskc1pg3235dkw19"></a>

In SDK Bidding, DT Exchange must first generate a token for the Mediation SDK to use when identifying the request to the server.

Use `getBidderToken` to generate a Bidder Token in a background thread:

{% code title="Java" %}

```java
BidTokenProvider.getBidderToken();
```

{% endcode %}

Return type: `java.lang.String`. If an error occurs, the returned value is null.

If DT Exchange wins the auction, load the ad with the `signaldata (adm)` that was received from the server:

{% code title="Java" %}

```java
public void loadAd(String admPayload);
```

{% endcode %}

If the load is successful: `public void onInneractiveSuccessfulAdRequest(InneractiveAdSpot inneractiveAdSpot)` callback is invoked.

If the ad fails to load: `public void onInneractiveFailedAdRequest(InneractiveAdSpot inneractiveAdSpot, InneractiveErrorCode inneractiveErrorCode)` callback is invoked.

## Displaying the Ad <a href="#h_01hvkbkvne4v8pk5h0t1bx7ep5" id="h_01hvkbkvne4v8pk5h0t1bx7ep5"></a>

After a successful ad request, use `mSpot.isReady` to confirm the ad is ready and `controller.show(this);` to display the Ad:

{% code title="Java" %}

```java
// Check if we have ad content
if (mSpot.isReady()) {
// Get the spot's controller
    InneractiveFullscreenUnitController controller = (InneractiveFullscreenUnitController)mSpot.getSelectedUnitController();
// Show the ad using the Activity's context
    controller.show(this);
}
```

{% endcode %}

## Releasing an Ad Placement <a href="#releasing-an-a-d-placement-0-17" id="releasing-an-a-d-placement-0-17"></a>

DT recommends releasing the allocated resources for ad display. For more information, see [Releasing Ad Instance Resources](https://docs.digitalturbine.com/dt-exchange/publishers/sdk-configuration/integrating-the-android-sdk/releasing-ad-instance-resources).
