Class NativeAdLoader

java.lang.Object
com.codename1.ads.NativeAdLoader

public class NativeAdLoader extends java.lang.Object

Loads NativeAd assets that you render with your own components, so the ad matches the look and feel of the surrounding content. This is the format to use in content driven apps - a news or social feed, a store listing, a chat or a search results screen - where a banner would feel bolted on but a list row styled like the others reads naturally (and must be clearly labelled "Ad"/"Sponsored").

Native ads are an optional provider capability; if the active provider does not support them the error callback receives an AdError with code AdError.CODE_UNSUPPORTED.

new NativeAdLoader("ca-app-pub-xxx/yyy").load(null,
    ad -> feed.addComponent(buildSponsoredRow(ad)),
    err -> Log.p(err.toString()));
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a loader for the given ad unit id.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    True when the active provider supports native ads.
    void
    load(AdRequest request, AdCallback<NativeAd> onSuccess, AdCallback<AdError> onError)
    Loads a native ad.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NativeAdLoader

      public NativeAdLoader(String adUnitId)

      Creates a loader for the given ad unit id.

      Parameters
      • adUnitId: the ad unit identifier from the network console
  • Method Details

    • isSupported

      public static boolean isSupported()
      True when the active provider supports native ads.
    • load

      public void load(AdRequest request, AdCallback<NativeAd> onSuccess, AdCallback<AdError> onError)

      Loads a native ad. Exactly one callback is invoked, on the EDT.

      Parameters
      • request: optional targeting metadata, may be null
      • onSuccess: invoked with the loaded ad
      • onError: invoked on failure