Skip to end of metadata
Go to start of metadata

Show Native Ads on Android

Native ads give you the ability to create ads that are customized to match the look and feel of the rest of your application. This page describes our Native Ads API at a high level, and includes a usage example. For a complete reference, see the Android SDK Reference.

Native networks supported through mediation:

  • Mopub
  • inMobi
  • Facebook
  • Yahoo Flurry
  • AdMob and DFP

In order to serve native ads, you will send a native ad request, and receive a native ad response. For Android 9 and above and API v. 28 and above, the request must be HTTPS by default in order to track viewability accurately.  You can enable HTTPS with useHttps(true).

In the example code below, we:

  • Set up a request object and supply it with either:
    • The placement ID (as shown in the example code below), OR
    • A combination of inventory code and member ID:

  • Optionally, you can set the renderer_id  for this NativeAdRequest. (For more on renderer_id see Native Layout Service.) The renderer_id needs to be specified in order for vastxml, likes, downloads, saleprice, phone, address, and display URL to be returned in the NativeAdResponse.

  • Register a listener that will signal native ad events such as clicks (NativeAdEventListener).
  • Register a listener to signal the state of the native request: success or failure. The listener must implement the NativeAdRequestListener interface.
  • If the request is successful (i.e., NativeAdListener.onAdLoaded() fires), native ad assets are loaded in the NativeAdResponse object which can be used in views that match the native look of the app. Then register the parent or container view of these views to enable impression and click tracking.
  • Unregister the native ad view after we're finished with it.

Maintain references to native views and native response objects

Maintain references to native views and native response objects.

It is your responsibility to keep a reference to the native ad view and NativeAdResponse object if necessary.

Fields Supported in Native

As of version 5.0 of the Mobile SDK, support for native assets is aligned with how native creatives are set up in Xandr's UI.

If you are still using Legacy Native in Xandr's UI, you will need to move to "New" Native for your creatives.

The following is a comprehensive list of native assets supported in the SDKs.

AssetSupported Pre 5.0?Supported Post 5.0?v5.0+ API-Usage Example
Image, Width, HeightYes, Yes, YesYes, Yes, Yes
Icon+Width+HeightYes, No, NoYes, Yes, Yes
Sponsored byYesYes
Body textYesYes
Rating, ScaleYes, YesYes, No
LikesNoYes (json only)
if((nativeAdResponse.getNetworkIdentifier() == NativeAdResponse.Network.APPNEXUS) &&. (nativeAdResponse.getNativeElements().get(NativeAdResponse.NATIVE_ELEMENT_OBJECT)) instanceof JSONObject){
JSONObject nativeResponseJSON = (JSONObject) (nativeAdResponse.getNativeElements().get(NativeAdResponse.NATIVE_ELEMENT_OBJECT));
    String likes = JsonUtil.getJSONString(nativeResponseJSON,"likes");
String downloads = JsonUtil.getJSONString(nativeResponseJSON,"downloads");
String price = JsonUtil.getJSONString(nativeResponseJSON,"price");
String saleprice = JsonUtil.getJSONString(nativeResponseJSON,"saleprice");
String phone = JsonUtil.getJSONString(nativeResponseJSON,"phone");
String address = JsonUtil.getJSONString(nativeResponseJSON,"address");
String displayurl = JsonUtil.getJSONString(nativeResponseJSON,"displayurl");
DownloadsNoYes (json only)
PriceNoYes (json only)
Sale PriceNoYes (json only)
PhoneNoYes (json only)
AddressNoYes (json only)
Display URLNoYes (json only)
Privacy URLNoYes
Full textYesNo 

Related Topics