NativeAd

public abstract class NativeAd


A Google native ad.

Summary

Nested types

public abstract class NativeAd.AdChoicesInfo

Attribution information.

public abstract class NativeAd.Image

A native ad image asset.

Interface definition for a callback to be invoked when a native ad has successfully loaded.

A listener interface apps can use to receive unconfirmed click events when using the Confirmed Click feature.

Public constructors

Public methods

abstract void

Cancels an unconfirmed click that was previously recorded for the ad.

abstract void

Destroys the ad object.

abstract void

This method is deprecated.

Use enableCustomClickGestureDirection.

abstract @Nullable NativeAd.AdChoicesInfo

Returns the information for the AdChoices attribution.

abstract @Nullable String

Returns text that identifies the advertiser.

abstract @Nullable String

Returns body text.

abstract @Nullable String

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

abstract Bundle

Returns a bundle of extra assets associated with the native ad.

abstract @Nullable String

Returns the primary text headline.

abstract @Nullable NativeAd.Image

Returns a small image identifying the advertiser.

abstract List<NativeAd.Image>

Returns a list of large images.

abstract @Nullable MediaContent

Returns the MediaContent associated with this ad.

abstract List<MuteThisAdReason>

Returns Mute This Ad reasons available for this ad.

abstract @Nullable String

For ads about apps, returns a string representing how much the app costs.

abstract @Nullable ResponseInfo

Returns the ResponseInfo object for the loaded ad.

abstract @Nullable Double

For ads about apps, returns a star rating from 0 to 5 representing how many stars the app has in the store offering it.

abstract @Nullable String

For ads about apps, returns the name of the store offering the app for download.

abstract boolean

This method is deprecated.

When loading an ad using enableCustomClickGestureDirection, all ads returned will support custom click gesture.

abstract boolean

Returns true if this ad can be muted programmatically.

abstract void
muteThisAd(MuteThisAdReason muteThisAdReason)

Mutes This Ad programmatically.

abstract void
performClick(Bundle clickData)

Should be called when the user has clicked on the ad.

abstract void

This method is deprecated.

The Google Mobile Ads SDK now tracks custom click gestures using the click gesture direction requested in enableCustomClickGestureDirection.

abstract boolean
recordImpression(Bundle impressionData)

Should be called when the ad is first displayed.

abstract void
reportTouchEvent(Bundle touchEventData)

Should be called when a touch event happens on the ad.

abstract void

Sets the MuteThisAdListener for the ad.

abstract void

Register a callback to be invoked when this ad is estimated to have earned money.

abstract void

Sets the UnconfirmedClickListener for the ad.

Public constructors

NativeAd

public NativeAd()

Public methods

cancelUnconfirmedClick

public abstract void cancelUnconfirmedClick()

Cancels an unconfirmed click that was previously recorded for the ad.

destroy

public abstract void destroy()

Destroys the ad object. No other methods should be called on the ad object after destroy is called.

enableCustomClickGesture

public abstract void enableCustomClickGesture()

Enables publishers reporting clicks using custom gestures for this NativeAd. The ad unit must be allowlisted to be able to use this method.

By default SDK tracks clicks on asset views. If this method is called, SDK will no longer track clicks for this NativeAd. It should be called before showing the ad.

getAdChoicesInfo

public abstract @Nullable NativeAd.AdChoicesInfo getAdChoicesInfo()

Returns the information for the AdChoices attribution.

getAdvertiser

public abstract @Nullable String getAdvertiser()

Returns text that identifies the advertiser. Apps are not required to display this asset, though it's recommended.

getBody

public abstract @Nullable String getBody()

Returns body text. Apps are required to display this asset.

getCallToAction

public abstract @Nullable String getCallToAction()

Returns the ad's call to action (such as "Buy" or "Install"). Apps are not required to display this asset, though it's recommended.

getExtras

public abstract Bundle getExtras()

Returns a bundle of extra assets associated with the native ad. If a mediation partner's ad have assets besides the standard ones (price, store, etc.), they can be set by calling the method in setExtras, and can be retrieved via this method. For non-mediation flow, it returns an empty bundle.

getHeadline

public abstract @Nullable String getHeadline()

Returns the primary text headline. Apps are required to display this asset.

getIcon

public abstract @Nullable NativeAd.Image getIcon()

Returns a small image identifying the advertiser. Apps are not required to display this asset, though it's recommended.

getImages

public abstract List<NativeAd.ImagegetImages()

Returns a list of large images. Apps are not required to display this asset, though it's recommended.

getMediaContent

public abstract @Nullable MediaContent getMediaContent()

Returns the MediaContent associated with this ad.

getMuteThisAdReasons

public abstract List<MuteThisAdReasongetMuteThisAdReasons()

Returns Mute This Ad reasons available for this ad. Use the text description from class for showing to user.

getPrice

public abstract @Nullable String getPrice()

For ads about apps, returns a string representing how much the app costs. Apps are not required to display this asset, though it's recommended.

getResponseInfo

public abstract @Nullable ResponseInfo getResponseInfo()

Returns the ResponseInfo object for the loaded ad. Returns null until the ad successfully loads.

getStarRating

public abstract @Nullable Double getStarRating()

For ads about apps, returns a star rating from 0 to 5 representing how many stars the app has in the store offering it. Apps are not required to display this asset, though it's recommended.

getStore

public abstract @Nullable String getStore()

For ads about apps, returns the name of the store offering the app for download. For example, "Google Play". Apps are not required to display this asset, though it's recommended.

isCustomClickGestureEnabled

public abstract boolean isCustomClickGestureEnabled()

Indicates whether clicks can be reported using custom click gestures. Reach out to your account manager to allowlist your ad unit for this feature.

isCustomMuteThisAdEnabled

public abstract boolean isCustomMuteThisAdEnabled()

Returns true if this ad can be muted programmatically. Use setRequestCustomMuteThisAd to request custom implementation of Mute This Ad.

muteThisAd

public abstract void muteThisAd(MuteThisAdReason muteThisAdReason)

Mutes This Ad programmatically.

Parameters
MuteThisAdReason muteThisAdReason

The mute reason selected by the user. Get mute reasons from getMuteThisAdReasons. Use null to Mute This Ad with default reason.

performClick

public abstract void performClick(Bundle clickData)

Should be called when the user has clicked on the ad. The ad unit must be allowlisted to be able to use this api. This method should only be used by Unity plugin publishers.

Parameters
Bundle clickData

bundle of the app environment when the click happens. For details to construct the click data Bundle, see NativeAdConstants.

recordCustomClickGesture

public abstract void recordCustomClickGesture()

Reports clicks for this NativeAd using custom click gesture. The ad unit must be allowlisted to be able to use this method.

enableCustomClickGesture must be called before calling this method.

recordImpression

public abstract boolean recordImpression(Bundle impressionData)

Should be called when the ad is first displayed. The ad unit must be allowlisted to be able to use this api.

Parameters
Bundle impressionData

bundle of the app environment when the impression happens. For details to construct the click data Bundle, see NativeAdConstants.

Returns
boolean

true if the impression is recorded successfully

reportTouchEvent

public abstract void reportTouchEvent(Bundle touchEventData)

Should be called when a touch event happens on the ad. The ad unit must be allowlisted to be able to use this api. If you are interested in using this feature, reach out to your account manager.

Parameters
Bundle touchEventData

bundle of touch event coordinates and duration.

Example JSON representation of touchEventData Bundle:

  {    "x": "100",  // The x-coordinate of the touch event relative to the window.    "y": "50",  // The y-coordinate of the touch event relative to the window.    "duration_millis": "500",  // The amount of milliseconds the user pressed on the asset.  }

setMuteThisAdListener

public abstract void setMuteThisAdListener(MuteThisAdListener listener)

Sets the MuteThisAdListener for the ad.

setOnPaidEventListener

public abstract void setOnPaidEventListener(@Nullable OnPaidEventListener listener)

Register a callback to be invoked when this ad is estimated to have earned money.

setUnconfirmedClickListener

public abstract void setUnconfirmedClickListener(
    NativeAd.UnconfirmedClickListener listener
)

Sets the UnconfirmedClickListener for the ad.