NativeAdMapper

public abstract class NativeAdMapper


Mapping class for Google AdMob native ads.

Mediation adapters that load a native ad must extend this class to provide a mapping from the mediated ad network's native ad object to com.google.android.gms.ads.nativead.NativeAd.

Summary

Public constructors

NativeAdMapper(
    String headline,
    List<@NonNull NativeAd.Image> images,
    String body,
    NativeAd.Image icon,
    String callToAction,
    String advertiser,
    Double starRating,
    String store,
    String price,
    VideoController videoController,
    boolean hasVideoContent,
    NativeAd.AdChoicesInfo attributionInfo,
    View adChoicesContent,
    View mediatedMediaView,
    Object mediatedAd,
    @NonNull Bundle extras,
    boolean overrideImpressionRecording,
    boolean overrideClickHandling,
    float mediaContentAspectRatio
)

Public methods

void

Subclasses should implement this method if the mediated network offers a way to destroy the native ad object.

final View

A view to be used as AdChoices content.

final String

A text that identifies the advertiser.

final String

The body text asset.

final String

The ad's call to action (such as "Buy" or "Install").

final float
final float
final @NonNull Bundle

A bundle of extras containing assets or attributes that do not directly map to those expected for a Google native ad object (headline, body, etc).

final boolean

The current ad has video content.

final String

The primary text headline.

final NativeAd.Image

A small image identifying the advertiser.

final List<@NonNull NativeAd.Image>

A list of large images.

final float

The aspect ratio of the media to be rendered.

final Object

The mediated native ad object.

final boolean

A boolean representing whether the ad network does click handling on its own.

final boolean

A boolean representing whether the ad network does impression tracking on its own.

final String

A string representing how much the app costs.

final Double

A star rating from 0 to 5 representing how many stars the app has in the store offering it.

final String

The name of the store offering the app for download.

void

Subclasses should implement this method if the network requires the developer to explicitly handle click events of views rendered to screen.

final boolean
void

Subclasses should implement this method if the network requires the developer to explicitly record an impression of a view rendered to screen.

final void
setAdChoicesContent(View adChoicesContent)

A view to be used as AdChoices content.

final void
setAdvertiser(String advertiser)

A text that identifies the advertiser.

final void

The body text asset.

final void
setCallToAction(String callToAction)

The ad's call to action (such as "Buy" or "Install").

final void

A bundle of extras containing assets or attributes that do not directly map to those expected for a Google native ad object (headline, body, etc).

final void
setHasVideoContent(boolean hasVideoContent)

The current ad has video content.

final void
setHeadline(String headline)

The primary text headline.

final void

A small image identifying the advertiser.

final void

A list of large images.

final void
setMediaContentAspectRatio(float mediaContentAspectRatio)

The aspect ratio of the media to be rendered.

final void
final void
setMediatedAd(Object mediatedAd)

The mediated native ad object.

final void
setOverrideClickHandling(boolean overrideClickHandling)

A boolean representing whether the ad network does click handling on its own.

final void
setOverrideImpressionRecording(boolean overrideImpressionRecording)

A boolean representing whether the ad network does impression tracking on its own.

final void

A string representing how much the app costs.

final void
setStarRating(Double starRating)

A star rating from 0 to 5 representing how many stars the app has in the store offering it.

final void

The name of the store offering the app for download.

void
trackViews(
    View containerView,
    @NonNull Map<@NonNull String, @NonNull View> clickableAssetViews,
    @NonNull Map<@NonNull String, @NonNull View> nonclickableAssetViews
)

Subclasses should implement this method if the network requires the developer to prepare state for recording an impression and/or click before a view is rendered to screen.

void

Subclasses should implement this method if the mediated network's SDK offers a way to stop tracking a native ad view for the ad mapped by this object.

Public constructors

NativeAdMapper

public NativeAdMapper(
    String headline,
    List<@NonNull NativeAd.Image> images,
    String body,
    NativeAd.Image icon,
    String callToAction,
    String advertiser,
    Double starRating,
    String store,
    String price,
    VideoController videoController,
    boolean hasVideoContent,
    NativeAd.AdChoicesInfo attributionInfo,
    View adChoicesContent,
    View mediatedMediaView,
    Object mediatedAd,
    @NonNull Bundle extras,
    boolean overrideImpressionRecording,
    boolean overrideClickHandling,
    float mediaContentAspectRatio
)

Public methods

destroy

public void destroy()

Subclasses should implement this method if the mediated network offers a way to destroy the native ad object.

getAdChoicesContent

public final View getAdChoicesContent()

A view to be used as AdChoices content.

getAdvertiser

public final String getAdvertiser()

A text that identifies the advertiser.

getBody

public final String getBody()

The body text asset. Adapters should always map this asset since it is always included for Google ads.

getCallToAction

public final String getCallToAction()

The ad's call to action (such as "Buy" or "Install"). Adapters should always map this asset since it is always included for Google ads.

getCurrentTime

public final float getCurrentTime()

getDuration

public final float getDuration()

getExtras

public final @NonNull Bundle getExtras()

A bundle of extras containing assets or attributes that do not directly map to those expected for a Google native ad object (headline, body, etc).

getHasVideoContent

public final boolean getHasVideoContent()

The current ad has video content.

getHeadline

public final String getHeadline()

The primary text headline. Adapters should always map this asset since it is always included for Google ads.

getIcon

public final NativeAd.Image getIcon()

A small image identifying the advertiser.

getImages

public final List<@NonNull NativeAd.ImagegetImages()

A list of large images. Adapters should always map this asset since it is always included for Google ads.

getMediaContentAspectRatio

public final float getMediaContentAspectRatio()

The aspect ratio of the media to be rendered.

getMediatedAd

public final Object getMediatedAd()

The mediated native ad object. Publishers have the option of accessing it directly to use APIs not fully mapped by the Mobile Ads SDK.

getOverrideClickHandling

public final boolean getOverrideClickHandling()

A boolean representing whether the ad network does click handling on its own.

getOverrideImpressionRecording

public final boolean getOverrideImpressionRecording()

A boolean representing whether the ad network does impression tracking on its own.

getPrice

public final String getPrice()

A string representing how much the app costs.

getStarRating

public final Double getStarRating()

A star rating from 0 to 5 representing how many stars the app has in the store offering it.

getStore

public final String getStore()

The name of the store offering the app for download. For example, "Google Play".

handleClick

public void handleClick(@NonNull View view)

Subclasses should implement this method if the network requires the developer to explicitly handle click events of views rendered to screen.

hasVideoContent

public final boolean hasVideoContent()

recordImpression

public void recordImpression()

Subclasses should implement this method if the network requires the developer to explicitly record an impression of a view rendered to screen.

setAdChoicesContent

public final void setAdChoicesContent(View adChoicesContent)

A view to be used as AdChoices content.

setAdvertiser

public final void setAdvertiser(String advertiser)

A text that identifies the advertiser.

setBody

public final void setBody(String body)

The body text asset. Adapters should always map this asset since it is always included for Google ads.

setCallToAction

public final void setCallToAction(String callToAction)

The ad's call to action (such as "Buy" or "Install"). Adapters should always map this asset since it is always included for Google ads.

setExtras

public final void setExtras(@NonNull Bundle extras)

A bundle of extras containing assets or attributes that do not directly map to those expected for a Google native ad object (headline, body, etc).

setHasVideoContent

public final void setHasVideoContent(boolean hasVideoContent)

The current ad has video content.

setHeadline

public final void setHeadline(String headline)

The primary text headline. Adapters should always map this asset since it is always included for Google ads.

setIcon

public final void setIcon(NativeAd.Image icon)

A small image identifying the advertiser.

setImages

public final void setImages(List<@NonNull NativeAd.Image> images)

A list of large images. Adapters should always map this asset since it is always included for Google ads.

setMediaContentAspectRatio

public final void setMediaContentAspectRatio(float mediaContentAspectRatio)

The aspect ratio of the media to be rendered.

setMediaView

public final void setMediaView(@NonNull View mediaView)

setMediatedAd

public final void setMediatedAd(Object mediatedAd)

The mediated native ad object. Publishers have the option of accessing it directly to use APIs not fully mapped by the Mobile Ads SDK.

setOverrideClickHandling

public final void setOverrideClickHandling(boolean overrideClickHandling)

A boolean representing whether the ad network does click handling on its own.

setOverrideImpressionRecording

public final void setOverrideImpressionRecording(boolean overrideImpressionRecording)

A boolean representing whether the ad network does impression tracking on its own.

setPrice

public final void setPrice(String price)

A string representing how much the app costs.

setStarRating

public final void setStarRating(Double starRating)

A star rating from 0 to 5 representing how many stars the app has in the store offering it.

setStore

public final void setStore(String store)

The name of the store offering the app for download. For example, "Google Play".

trackViews

public void trackViews(
    View containerView,
    @NonNull Map<@NonNull String, @NonNull View> clickableAssetViews,
    @NonNull Map<@NonNull String, @NonNull View> nonclickableAssetViews
)

Subclasses should implement this method if the network requires the developer to prepare state for recording an impression and/or click before a view is rendered to screen. Find the asset names in {@link NativeAdAssetNames}.

Parameters
View containerView

The container {@link View} for the ad.

@NonNull Map<@NonNull String, @NonNull View> clickableAssetViews

The {@link Map} of clickable asset names to corresponding {@link View}.

@NonNull Map<@NonNull String, @NonNull View> nonclickableAssetViews

The {@link Map} of non-clickable asset names to corresponding {@link View}.

untrackView

public void untrackView(View view)

Subclasses should implement this method if the mediated network's SDK offers a way to stop tracking a native ad view for the ad mapped by this object.