> 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/nativead.md).

# NativeAd

**package com.intowow\.sdk**

**public class NativeAd extends Ad**

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

### Characteristics

* Support image and video.
* Video is mute by default, and can be toggled by clicking it.
* Creative, title and description of ad are accessible to app for customized layout.

### Recommended Ad Placement

* [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 NativeAd mNativeAd = new NativeAd(mActivity);
private MediaView mMediaView = null;

RequestInfo requestInfo = new RequestInfo();
requestInfo.setPlacement(PLACEMENT_NAME);
requestInfo.setTimeout(LOAD_AD_TIMEOUT);

mNativeAd.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) {
    }
});

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

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

        //  Get ad title string.
        String title = mNativeAd.getAdTitle()
    
        //  Get ad description string.
        String adBody = mNativeAd.getAdBody();
    
        //  Get call to action string.
        String callToAction = mNativeAd.getAdCallToAction();
    
        //  Instantiate MediaView
        //  please make sure to pass activity on to the mediaview
        //
        int width = your_defined_width;
        mMediaView = new MediaView(activity);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
          width, RelativeLayout.LayoutParams.WRAP_CONTENT);
        mMediaView.setLayoutParams(params);
        mMediaView.setNativeAd(mNativeAd);
    
        //  Add these materials to the UI hierarchy
    }
});
```

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

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

    if(mNativeAd != null) {
        mNativeAd.destroy();
        mNativeAd = null;
    }
    ...
    ...
    super.onDestroy();
}
```

### Advance Integration

* After ad loading, you can configure your ad by using `AdProperty`with [MediaView](https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/mediaview.html) class.
* You could use [hasVideoContent()](/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/nativead.md#hasVideoContent) to check if the ad is video or not after ad loaded.

### 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/nativead.md#NativeAd">NativeAd(Context context)</a> <br> Instantiates a new native ad.</p> |

| Public methods                                                                                     |                                                                                                                                                                                                                                                               |
| -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/nativead.md#destroy">destroy()</a> <br> Release the native ad.</p>                                                                                                                |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/nativead.md#downloadAndDisplayImage">downloadAndDisplayImage(NativeAd.Image image, ImageView imageView)</a> <br> Download and set image to imageView.</p>                         |
| String                                                                                             | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/nativead.md#getAdBody">getAdBody()</a> <br> Get the ad description. <br> <strong>you can call this method after onAdLoaded() of AdListener.</strong> </p>                         |
| String                                                                                             | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/nativead.md#getAdCallToAction">getAdCallToAction()</a> <br> Get the ad call to action text. <br> <strong>you can call this method after onAdLoaded() of AdListener.</strong> </p> |
| Image                                                                                              | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/nativead.md#getAdIcon">getAdIcon()</a> <br> Get the ad icon. <br> <strong>you can call this method after onAdLoaded() of AdListener.</strong> </p>                                |
| String                                                                                             | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/nativead.md#getAdTitle">getAdTitle()</a> <br>Get the ad title. <br><strong>You can call this method after onAdLoaded() of AdListener.</strong> </p>                               |
| [CERequestResult](/crystalexpress-documentation-v3-x/android-sdk/api-reference/cerequestresult.md) | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/nativead.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/nativead.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/nativead.md#registerViewForInteraction1">registerViewForInteraction(View v)</a> <br> Register view for interaction.</p>                                                           |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/nativead.md#registerViewForInteraction2">registerViewForInteraction(View v, List clickableViews)</a> <br> Register view for interaction.</p>                                      |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/nativead.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/nativead.md#setOnTouchListener">setOnTouchListener(OnTouchListener listener)</a> <br> Set onTouchListener.</p>                                                                    |
| void                                                                                               | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/nativead.md#unregisterView">unregisterView()</a> <br> Unregister view.</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

### NativeAd <a href="#nativead" id="nativead"></a>

NativeAd(Context context, String placement)

Instantiates a new native ad.

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

## Public methods

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

void destroy()

Release the ad.

### downloadAndDisplayImage <a href="#downloadanddisplayimage" id="downloadanddisplayimage"></a>

void downloadAndDisplayImage()

Download and display image. **you can call this method after onAdLoaded() of AdListener.**&#x20;

### getAdBody <a href="#getadbody" id="getadbody"></a>

String getAdBody()

Get the ad description. **you can call this method after onAdLoaded() of AdListener.**&#x20;

| Returns |                     |
| ------- | ------------------- |
| String  | the ad description. |

### getAdCallToAction <a href="#getadcalltoaction" id="getadcalltoaction"></a>

String getAdCallToAction()

Get the ad call to action text. **you can call this method after onAdLoaded() of AdListener.**&#x20;

| Returns |                             |
| ------- | --------------------------- |
| String  | the ad call to action text. |

### getAdIcon <a href="#getadicon" id="getadicon"></a>

Image getAdIcon()

Get the ad icon. **you can call this method after onAdLoaded() of AdListener.**&#x20;

| Returns |                                                                                                                                                                  |
| ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Image   | the ad icon. you can get icon url to download the icon file by calling `image.getUrl()`, and get icon size by calling `image.getWidth()` and `image.getHeight()` |

### getAdTitle <a href="#getadtitle" id="getadtitle"></a>

String getAdTitle()

Get the ad title. **you can call this method after onAdLoaded() of AdListener.**&#x20;

| Returns |               |
| ------- | ------------- |
| String  | the ad title. |

### 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  |

### registerViewForInteraction(View v) <a href="#registerviewforinteraction1" id="registerviewforinteraction1"></a>

void registerViewForInteraction(View v)

Register view for interaction.

| Parameters |                                 |
| ---------- | ------------------------------- |
| v          | View: the view for interaction. |

### registerViewForInteraction(View v, List clickableViews) <a href="#registerviewforinteraction2" id="registerviewforinteraction2"></a>

void registerViewForInteraction(View v, List clickableViews)

Register view for interaction.

| Parameters     |                                 |
| -------------- | ------------------------------- |
| v              | View: the view for interaction. |
| clickableViews | List: views for interaction.    |

### 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. |

### setOnTouchListener <a href="#setontouchlistener" id="setontouchlistener"></a>

void setOnTouchListener(OnTouchListener listener)

Set onTouchListener.

| Parameters |                                       |
| ---------- | ------------------------------------- |
| listener   | OnTouchListener: the onTouchListener. |

### unregisterView <a href="#unregisterview" id="unregisterview"></a>

void unregisterView()

Unregister view.
