> For the complete documentation index, see [llms.txt](https://intowow.gitbook.io/crystalexpress-documentation-v3-x/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://intowow.gitbook.io/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md).

# DispayAd

**package com.intowow\.sdk**

**public class DisplayAd extends Ad**

![](https://1252529651-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGU_q6Cp7glylaa3ogy%2F-LGU_uDXyKLpZsKhgGZa%2F-LGU_z7HYLrrZAh5ywGr%2Fcard.png?generation=1530612180923061\&alt=media)

### Characteristics

* Support image and video.
* Video is mute by default, and can be toggled by clicking it.

### Recommended Ad Placement

* [Launch screen](/crystalexpress-documentation-v3-x/android-sdk/integration-scenarios/launch-screen.md)
* [In Feed](/crystalexpress-documentation-v3-x/android-sdk/integration-scenarios/in-feed.md)
* [Result Page](/crystalexpress-documentation-v3-x/android-sdk/integration-scenarios/result-page.md)
* Custom

### Request an ad

* You could request an ad by:

```java
private final static String PLACEMENT_NAME = "Obtain from your Intowow account manager";
private final static long LOAD_AD_TIMEOUT = 30000L;

private DisplayAd mDisplayAd = new DisplayAd(mActivity);
RequestInfo requestInfo = new RequestInfo();
requestInfo.setPlacement(PLACEMENT_NAME);
requestInfo.setTimeout(LOAD_AD_TIMEOUT);

mDisplayAd.setAdListener(new CEAdListener() {

    @Override
    public void onAdClicked(Ad ad) {
    }

    @Override
    public void onAdImpression(Ad ad) {
    }

    @Override
    public void onAdMute(Ad ad) {
    }

    @Override
    public void onAdUnmute(Ad ad) {
    }

    @Override
    public void onVideoStart(Ad ad) {
    }

    @Override
    public void onVideoProgress(Ad ad, int totoalDuration, int currentPosition) {
    }

    @Override
    public void onVideoEnd(Ad ad) {
    }
});

mDisplayAd.loadAdAsync(requestInfo, new CEAdRequestListener() {
    @Override
    public void onError(Ad ad, AdError error) {
        adErrorProcess(error);
    }

    @Override
    public void onAdLoaded(Ad ad) {
        if (ad != mDisplayAd) {
            return;
        }
        adLoadedProcess();
    }
});
```

* remember to release ad if it is no longer to use.

```java
@Override
protected void onDestroy() {
    if(mDisplayAd != null) {
        mDisplayAd.destroy();
        mDisplayAd = null;
    }
    ...
    ...
    super.onDestroy();
}
```

### Advance Integration

* You could use `AdProperty` to configure your ad if necessary:

```java
Map<String, Object> adProps = new HashMap<String, Object>();
adProps.put(AdProperty.VIDEO_AUTO_REPEAT, trueOrFalse);
adProps.put(AdProperty.HIDE_AD_ICON, trueOrFalse);
adProps.put(AdProperty.SILENT_START, trueOrFalse);

DisplayAd mDisplayAd = new DisplayAd(context, adProps);
```

* `AdProperty.VIDEO_AUTO_REPEAT`: if video auto repeat or not, the default value is true.
* `AdProperty.HIDE_AD_ICON`: if need to hide the ad icon, the default value is false.
* `AdProperty.SILENT_START`: auto silent play, the default value is true.
* You could use [setWidth(int width)](/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#setWidth) to instruct SDK to set an expected width of the ad, and SDK will rescale the ad automatically and keeps the aspect ratio.
* You could use [hasVideoContent()](/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#hasVideoContent) to check if the ad is video or not after ad loaded.
* If you want to resize the ad, please use [resize(int width)](/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#resize).

### NOTE

* Please make sure to new an instance before requesting the ad. Do not keep the returned ad too long, otherwise you may display the out-of-dated ad.

| Public constructors                                                                                                                                                                     |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#DisplayAd1">DisplayAd(Context context)</a> <br> Instantiates a new display ad.</p>              |
| <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#DisplayAd2">DisplayAd(Context context, Map adProps)</a> <br> Instantiates a new display ad.</p> |

| Public methods                                                                                     |                                                                                                                                                                                                                                                                                                                            |
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#destroy">destroy()</a> <br> Release the display ad.</p>                                                                                                                                                                            |
| View                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#getView1">getView()</a> <br> Get the ad view. <br> <strong>You should call this method after ad loaded.</strong></p>                                                                                                               |
| View                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#getView2">getView(Activity activity)</a> <br> Get the ad view. <br> <strong>You should call this method after ad loaded.</strong></p>                                                                                              |
| boolean                                                                                            | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#isAvailableAttachToWindow">isAvailableAttachToWindow()</a> <br> Checks if this ad is available to attach to window or not.</p>                                                                                                     |
| boolean                                                                                            | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#isMute">isMute()</a> <br> Checks if this ad is on mute status or not.</p>                                                                                                                                                          |
| [CERequestResult](/crystalexpress-documentation-v3-x/android-sdk/api-reference/cerequestresult.md) | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#loadadinstant">loadAdInstant(RequestInfo requestInfo)</a> <br> Load ad with requestInfo (<strong>synchronous</strong>)</p>                                                                                                         |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#loadadasync">loadAdAsync(RequestInfo requestInfo, CEAdRequestListener listener)</a></p><p>Load ad with requestInfo (<strong>asynchronous</strong>)</p>                                                                             |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#mute">mute()</a> <br> Mute video ad.</p>                                                                                                                                                                                           |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#play">play()</a> <br> Allow the ad to play.</p>                                                                                                                                                                                    |
| boolean                                                                                            | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#resize">resize(int width)</a> <br> Resize the ad.</p>                                                                                                                                                                              |
| boolean                                                                                            | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#resize1">resize(CEAdSize ceAdSize)</a> <br> Resize the ad by CEAdSize.</p>                                                                                                                                                         |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#setAdListener">setAdListener(CEAdListener listener)</a> <br> Set the ad listener.</p>                                                                                                                                              |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#setIsVideoAutoRepeat">setIsVideoAutoRepeat(boolean isVideoAutoRepeat)</a> <br> set if the video ad should auto repeat or not. <br> <strong>You should call this method before loadAdInstant/loadAdAsync if necessary.</strong></p> |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#setPlace">setPlace(int place)</a> <br> Set the ad place.</p>                                                                                                                                                                       |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#setWidth">setWidth(int width)</a> <br> Set the ad width. <br> <strong>You should call this method before loadAdInstant/loadAdAsync if necessary.</strong></p>                                                                      |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#stop">stop()</a> <br> Disallow the ad to play.</p>                                                                                                                                                                                 |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#unmute">unmute()</a> <br> Unmute video ad.</p>                                                                                                                                                                                     |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/dispayad.md#setAdSize">setAdSize(CEAdSize ceAdSize)</a> <br> Set the ad view size by ad ratio. <br> <strong>You should call this method before loadAdInstant/loadAdAsync if necessary.</strong></p>                                            |

| Inherited methods |                                                                                                                                                                                                                                                                                                   |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| int               | <p><a href="https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/ad.html#getAdId">getAdId()</a> <br> Get the ad id.</p>                                                                                               |
| String            | <p><a href="https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/ad.html#getCampaignId">getCampaignId()</a> <br> Get the campaign id.</p>                                                                             |
| String            | <p><a href="https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/ad.html#getEngageUrl">getEngageUrl()</a> <br> Get the engage url.</p>                                                                                |
| int               | <p><a href="https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/ad.html#getPlace">getPlace()</a> <br> Get the ad place.</p>                                                                                          |
| String            | <p><a href="https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/ad.html#getPlacement">getPlacement()</a> <br> Get the ad placement.</p>                                                                              |
| Rect              | <p><a href="https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/ad.html#getSize">getSize()</a> <br> Get the ad size. <br> <strong>It should be called after onAdLoaded().</strong></p>                               |
| String            | <p><a href="https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/ad.html#getToken">getToken()</a> <br> Get the ad token for tracking.</p>                                                                             |
| long              | <p><a href="https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/ad.html#getTotalFileSize">getTotalFileSize()</a> <br> Get the ad file size on device.</p>                                                            |
| String            | <p><a href="https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/ad.html#getVideoCoverPath">getVideoCoverPath()</a> <br> Get video cover file path. <br> <strong>It should be called after onAdLoaded().</strong></p> |
| boolean           | <p><a href="https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/ad.html#hasVideoContent">hasVideoContent()</a> <br> Check if the ad has video content or not.</p>                                                    |
| boolean           | <p><a href="https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/ad.html#isValid">isValid()</a> <br> Check if the ad is still valid for serving.</p>                                                                  |
| void              | <p><a href="https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/ad.html#setSize">setSize(Rect rect)</a> <br> Set the ad size.</p>                                                                                    |

## Public constructors

### DisplayAd <a href="#displayad1" id="displayad1"></a>

DisplayAd(Context context)

Instantiates a new display ad.

| Parameters |                       |
| ---------- | --------------------- |
| context    | Context: the context. |

### DisplayAd <a href="#displayad2" id="displayad2"></a>

DisplayAd(Context context, String placement, Map\<String, Object> adProps)

Instantiates a new display ad.

| Parameters |                                        |
| ---------- | -------------------------------------- |
| context    | Context: the context.                  |
| adProps    | Map\<String, Object>: the ad property. |

## Public methods

### destroy <a href="#destroy" id="destroy"></a>

void destroy()

Release the ad.

### getView <a href="#getview1" id="getview1"></a>

View getView()

Gets the ad view. **You should call this method after onAdloaded().**

| Returns |              |
| ------- | ------------ |
| View    | the ad view. |

### getView <a href="#getview2" id="getview2"></a>

View getView(Activity activity)

Gets the ad view. **You should call this method after onAdloaded().**

| Parameters |                                                                                                                                                                              |
| ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| activity   | Activity: For Moat SDK tracking purpose. If you initiate the display ad without using activity and need to use Moat SDK, please use this API to initiate Moat SDK correctly. |

| Returns |              |
| ------- | ------------ |
| View    | the ad view. |

### isAvailableAttachToWindow <a href="#isavailableattachtowindow" id="isavailableattachtowindow"></a>

boolean isAvailableAttachToWindow()

Checks if this ad is available to attach to window or not.

| Returns |                                                                       |
| ------- | --------------------------------------------------------------------- |
| boolean | true the ad is available to attach the window otherwise return false. |

### isMute <a href="#ismute" id="ismute"></a>

boolean isMute()

Checks if this ad is on mute status or not.

| Returns |                                                           |
| ------- | --------------------------------------------------------- |
| boolean | true if this ad is on mute status otherwise return false. |

### loadAdInstant <a href="#loadadinstant" id="loadadinstant"></a>

[CERequestResult](/crystalexpress-documentation-v3-x/android-sdk/api-reference/cerequestresult.md) loadAdInstant(RequestInfo requestInfo)

Load ad with RequestInfo **(synchronous)**

| Parameters  |                                                                                                                                             |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| requestInfo | [RequestInfo](/crystalexpress-documentation-v3-x/android-sdk/api-reference/requestinfo.md): the request info such as placement and timeout. |

### loadAdAsync <a href="#loadadasync" id="loadadasync"></a>

void loadAdAsync(RequestInfo requestInfo, [CEAdRequestListener](/crystalexpress-documentation-v3-x/android-sdk/api-reference/ceadrequestlistener.md) listener)

Load ad with RequestInfo **(asynchronous)**

| Parameters  |                                                                                                                                             |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| requestInfo | [RequestInfo](/crystalexpress-documentation-v3-x/android-sdk/api-reference/requestinfo.md): the request info such as placement and timeout. |
| listener    | [CEAdRequestListener](/crystalexpress-documentation-v3-x/android-sdk/api-reference/ceadrequestlistener.md): know the result of loadAdAsync  |

### mute

void mute()

Mute video ad.

### play <a href="#play" id="play"></a>

void play()

Allow the ad to play.

### resize <a href="#resize" id="resize"></a>

boolean resize(int width)

Resize the ad.

| Parameters |                    |
| ---------- | ------------------ |
| width      | int: the ad width. |

| Returns |                                                         |
| ------- | ------------------------------------------------------- |
| boolean | true resize the ad successfully otherwise return false. |

### resize <a href="#resize1" id="resize1"></a>

boolean resize([CEAdSize](/crystalexpress-documentation-v3-x/android-sdk/api-reference/ceadsize.md) ceAdSize)

Resize the ad by CEAdSize.

| Parameters |                                                                                                     |
| ---------- | --------------------------------------------------------------------------------------------------- |
| ceAdSize   | [CEAdSize](/crystalexpress-documentation-v3-x/android-sdk/api-reference/ceadsize.md): the CEAdSize. |

| Returns |                                                         |
| ------- | ------------------------------------------------------- |
| boolean | true resize the ad successfully otherwise return false. |

### setAdListener <a href="#setadlistener" id="setadlistener"></a>

void setAdListener([CEAdListener](/crystalexpress-documentation-v3-x/android-sdk/api-reference/ceadlistener.md) listener)

Set the ad listener.

| Parameters |                                                                                                                |
| ---------- | -------------------------------------------------------------------------------------------------------------- |
| listener   | [CEAdListener](/crystalexpress-documentation-v3-x/android-sdk/api-reference/ceadlistener.md): the ad listener. |

### setIsVideoAutoRepeat <a href="#setisvideoautorepeat" id="setisvideoautorepeat"></a>

void setIsVideoAutoRepeat(boolean isVideoAutoRepeat)

Set if the video ad should auto repeat or not. **You should call this method before loadAd if necessary.**

| Parameters        |                                                                |
| ----------------- | -------------------------------------------------------------- |
| isVideoAutoRepeat | boolean: true the video ad should auto repeat otherwise false. |

### setPlace <a href="#setplace" id="setplace"></a>

void setPlace(int place)

Set the ad place.

| Parameters |                    |
| ---------- | ------------------ |
| place      | int: the ad place. |

### stop <a href="#stop" id="stop"></a>

void stop()

Disallow the ad to play.

### unmute <a href="#unmute" id="unmute"></a>

void unmute()

Unmute video ad.

### setAdSize <a href="#setadsize" id="setadsize"></a>

void setAdSize([CEAdSize](/crystalexpress-documentation-v3-x/android-sdk/api-reference/ceadsize.md) ceAdSize)

Set the ad view size by ad ratio. **You should call this method before loadAd if necessary.**

| Parameters |                                                                                                    |
| ---------- | -------------------------------------------------------------------------------------------------- |
| ceAdSize   | [CEAdSize](/crystalexpress-documentation-v3-x/android-sdk/api-reference/ceadsize.md): the CEAdSize |
