What is Native Ads Manager?

The Native Ads Manager is a way to pre-fetch Native Ads for your app. Use the Native Ads Manager when your user experience involves displaying multiple ads within a short amount of time, such as a vertical feed or horizontal scroll.

Implementation

Ensure you have completed the Audience Network Getting Started and Android Getting Started guides before you proceed.

Add the following line to the top of your activity class to import the Facebook Ads SDK:

import com.facebook.ads.*;

Initialize NativeAdsManager:

...
private NativeAdsManager manager; 
...
  
    @Override
    public void onCreate(Bundle savedInstanceState) {
      ...
      // Initialize a NativeAdsManager and request 5 ads
      manager = new NativeAdsManager(this, "YOUR_PLACEMENT_ID", 5);
      manager.setListener(new NativeAdsManager.Listener() {
        @Override
        public void onAdsLoaded() {
          //Ads Loaded callback
        }

        @Override
        public void onAdError(AdError adError) {
          // Ad error callback
        }
    });
  }

The maximum amount of ads per batch is 10 although we may deliver less ads than requested.

Try not to request significantly more ads than you think may be displayed as it may cause your placement to be throttled.

A batch of unique ads will be loaded in response to calling loadAds() and automatically refreshed by NativeAdsManager.

Once the app is ready to show an ad, call the nextNativeAd() method to retrieve an ad from the NativeAdsManager:

 NativeAd nativeAd = manager.nextNativeAd();

It is recommended that the app waits until immediately before rendering the ad content to call this method to ensure the best ad for the given context is used. Cloned ads will be returned if more than getUniqueNativeAdCount() ads are requested.

Note that nextNativeAd() can return null if there is no ad available. In this case please call loadAds() to refresh the loaded ads.

You can render the ad into a custom layout by following the Native Ads guide. Alternatively, you can use a Native Ad Template, or a Horizontal Scroll which displays a list of ads in a horizontal scroll view.

By default, the Native Ads Manager will refresh its ads periodically (every 30 minutes) so that you may initalize Native Ads Manager and leave the content refresh up to the Audience Network SDK. If you have used up all of the ads requested, then you will need to make a new request with the Native Ads Manager.

Next Steps