# Banner/MREC Ads

Banner and MREC ads are rectangular, image-based ads designed to be integrated directly into an app's content.

## Adding the Ad Placement (Ad Spot) <a href="#id-01k5nzh3m1wyxstxbwezhrwfj5" id="id-01k5nzh3m1wyxstxbwezhrwfj5"></a>

Add the Ad Placement `AdSpot` integration for the display unit, as well as the `AdView Controller`:

{% code title="Java" %}

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

// Adding the adview controller
InneractiveAdViewUnitController controller = new InneractiveAdViewUnitController();
mSpot.addUnitController(controller);
```

{% endcode %}

## Adding Listeners <a href="#id-01k60aefr2ey2c9krr59vjcytj" id="id-01k60aefr2ey2c9krr59vjcytj"></a>

Add listeners for the controller and the spot.

### Adding Event Listener for the Controller <a href="#h_01k6sw8901es4bj36exk9b1nmy" id="h_01k6sw8901es4bj36exk9b1nmy"></a>

The example below demonstrates how you would add an `EventListener` to receive Banner or MREC ad callbacks:

{% code title="Java" %}

```java
controller.setEventsListener(new InneractiveAdViewEventsListener() {
    @Override
    public void onAdImpression(InneractiveAdSpot adSpot) {
        Log.i(TAG, "onAdImpression");
    }
    @Override
    public void onAdClicked(InneractiveAdSpot adSpot) {
        Log.i(TAG, "onAdClicked");
    }
    @Override
    public void onAdWillCloseInternalBrowser(InneractiveAdSpot adSpot) {
        Log.i(TAG, "onAdWillCloseInternalBrowser");
    }
    @Override
    public void onAdWillOpenExternalApp(InneractiveAdSpot adSpot) {
        Log.i(TAG, "onAdWillOpenExternalApp");
    }
    @Override //Since VAMP 7.2.0
    public void onAdEnteredErrorState(InneractiveAdSpot adSpot, AdDisplayError error) {
        Log.i(TAG, "onAdEnteredErrorState");
    }
});
```

{% endcode %}

The `onAdEnteredErrorState` callback is invoked when the WebView renderer processes crash. For banner/MREC ads, destroy the current ad and request a replacement when `WebViewRendererProcessHasGoneError` occurs.

### Adding Request Listener for the Spot <a href="#h_01k6sw988vezzxgt8043x5p4b6" id="h_01k6sw988vezzxgt8043x5p4b6"></a>

The example below demonstrates how you would add a `RequestListener` for the Spot:

{% code title="Java" %}

```java
InneractiveAdSpot.RequestListener mSpotListener = new
InneractiveAdSpot.RequestListener() 
{
  @Override
  // When the ad request sends successfully.
  public void onInneractiveSuccessfulAdRequest(InneractiveAdSpot inneractiveAdSpot) {
  }
  @Override
  // When the ad request fails to send.
  public void onInneractiveFailedAdRequest(InneractiveAdSpot inneractiveAdSpot, InneractiveErrorCode inneractiveErrorCode) {
  }
};

mSpot.setRequestListener(mSpotListener);
```

{% endcode %}

## Fetching the Ad <a href="#h_01k6tc7br445b6t16x3kgp46jz" id="h_01k6tc7br445b6t16x3kgp46jz"></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="#h_01hvkbkvnd8ky2eqsxp1cqczjw" id="h_01hvkbkvnd8ky2eqsxp1cqczjw"></a>

In Waterfall mediation, use `InneractiveAdRequest adRequest` to request the ad:

{% code title="Java" %}

```java
InneractiveAdRequest adRequest = new InneractiveAdRequest("add_your_spot_id"); 
// To perform the ad request
mSpot.requestAd(adRequest);
```

{% endcode %}

After a successful ad request, use `mSpot.isReady` to confirm the ad is ready and `controller.bindView(layout);` to display.

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

In SDK Bidding, DT Exchange must first generate a token for the Mediation SDK to use when identifying the request to 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="#id-01k60adgzs5k1f2r6pnpe1wtfg" id="id-01k60adgzs5k1f2r6pnpe1wtfg"></a>

Define the ad layout in your XML file:

{% code title="XML" %}

```xml
<LinearLayout
android:id="@+id/inneractive_ad_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
```

{% endcode %}

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

{% code title="Java" %}

```java
// Check if we have ad content
if (mSpot.isReady()) {
// Getting the spot's controller
    InneractiveAdViewUnitController controller = (InneractiveAdViewUnitController)mSpot.getSelectedUnitController();
// Getting the ad view container
    ViewGroup layout = (ViewGroup)findViewById(R.id.inneractive_ad_layout);
// Showing the ad
    controller.bindView(layout);
}
```

{% 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).
