NativeAdRequest.Builder

public final class NativeAdRequest.Builder


A builder class for creating NativeAdRequest.

Summary

Public constructors

Builder(
    @NonNull String adUnitId,
    @NonNull List<@NonNull NativeAd.NativeAdType> nativeAdTypes
)

Public methods

final @NonNull NativeAdRequest.Builder

Sets a slot-level ad category exclusion label.

final @NonNull NativeAdRequest.Builder

Adds a keyword for targeting purposes.

final @NonNull NativeAdRequest

Constructs a NativeAdRequest with the specified attributes.

@NonNull NativeAdRequest.Builder

Indicates whether downloading image assets should be disabled by the SDK when loading an ad.

@NonNull NativeAdRequest.Builder
@CanIgnoreReturnValue
enableCustomClickGestureDirection(
    @NonNull NativeAd.SwipeGestureDirection customClickGestureDirection,
    boolean customClickGestureAllowTaps
)

Enables swipes as a custom click gesture.

final @NonNull NativeAdRequest.Builder

Adds extra parameters to pass to a specific ad source adapter.

final @NonNull NativeAdRequest.Builder

Adds a custom targeting parameter.

final @NonNull NativeAdRequest.Builder

Adds a custom targeting parameter with multiple values.

@NonNull NativeAdRequest.Builder

Sets the placement of the AdChoices icon (if available for the returned ad).

@NonNull NativeAdRequest.Builder

Sets the AdSize and overwrites any list of ad sizes passed in setAdSizes.

@NonNull NativeAdRequest.Builder

Sets a list of valid AdSizes and overwrites the ad size passed in setAdSize with the first size in the list.

final @NonNull NativeAdRequest.Builder

Sets the content URL for a web site whose content matches the app's primary content.

@NonNull NativeAdRequest.Builder

Sets custom native ad format IDs defined in the Ad Manager UI.

final @NonNull NativeAdRequest.Builder

Set extra parameters to pass to AdMob or Ad Manager.

@NonNull NativeAdRequest.Builder
setManualImpressionEnabled(boolean enabled)

Indicates whether you intend to record impressions manually for the BannerAd.

@NonNull NativeAdRequest.Builder

Sets the media aspect ratio.

final @NonNull NativeAdRequest.Builder

Sets URLs representing web content near an ad.

@NonNull NativeAdRequest.Builder

Sets a default placement ID for the loaded ad.

final @NonNull NativeAdRequest.Builder

Sets an identifier for use in frequency capping, audience segmentation and targeting, sequential ad rotation, and other audience-based ad delivery controls across devices.

final @NonNull NativeAdRequest.Builder

Sets the request agent string to identify the ad request's origin.

@NonNull NativeAdRequest.Builder

Sets the VideoOptions for this request.

Public constructors

Builder

public Builder(
    @NonNull String adUnitId,
    @NonNull List<@NonNull NativeAd.NativeAdType> nativeAdTypes
)

Public methods

addCategoryExclusion

@CanIgnoreReturnValue
public final @NonNull NativeAdRequest.Builder addCategoryExclusion(@NonNull String categoryExclusion)

Sets a slot-level ad category exclusion label.

This feature is only applicable for Ad Manager ad requests. Any category exclusions will be ignored on AdMob requests.

addKeyword

@CanIgnoreReturnValue
public final @NonNull NativeAdRequest.Builder addKeyword(@NonNull String keyword)

Adds a keyword for targeting purposes.

build

public final @NonNull NativeAdRequest build()

Constructs a NativeAdRequest with the specified attributes.

disableImageDownloading

@CanIgnoreReturnValue
public @NonNull NativeAdRequest.Builder disableImageDownloading()

Indicates whether downloading image assets should be disabled by the SDK when loading an ad. If called, the SDK will not download image assets and instead return a Image with just the URI and Scale properties populated. By default, the SDK will automatically download image assets and return a Image with all three properties (URI, Scale, and Drawable) populated.

enableCustomClickGestureDirection

@CanIgnoreReturnValue
public @NonNull NativeAdRequest.Builder enableCustomClickGestureDirection(
    @NonNull NativeAd.SwipeGestureDirection customClickGestureDirection,
    boolean customClickGestureAllowTaps
)

Enables swipes as a custom click gesture.

Available for allowlisted publishers only. These settings will be ignored for publishers not allowlisted.

Parameters
@NonNull NativeAd.SwipeGestureDirection customClickGestureDirection

The SwipeGestureDirection to be counted as a click.

boolean customClickGestureAllowTaps

Whether taps should still be allowed as clicks.

putAdSourceExtrasBundle

@CanIgnoreReturnValue
public final @NonNull NativeAdRequest.Builder putAdSourceExtrasBundle(
    @NonNull Class<@NonNull MediationExtrasReceiver> adapterClass,
    @NonNull Bundle adSourceExtras
)

Adds extra parameters to pass to a specific ad source adapter.

Parameters
@NonNull Class<@NonNull MediationExtrasReceiver> adapterClass

The Class of the adapter that should receive extras.

@NonNull Bundle adSourceExtras

A Bundle of extra information to pass to a mediation adapter.

putCustomTargeting

@CanIgnoreReturnValue
public final @NonNull NativeAdRequest.Builder putCustomTargeting(@NonNull String key, @NonNull String value)

Adds a custom targeting parameter. Calling this a second time with the same key will overwrite the old values.

This feature is only applicable for Ad Manager ad requests. Any custom targeting will be ignored on AdMob requests.

putCustomTargeting

@CanIgnoreReturnValue
public final @NonNull NativeAdRequest.Builder putCustomTargeting(
    @NonNull String key,
    @NonNull List<@NonNull String> values
)

Adds a custom targeting parameter with multiple values. Calling this a second time with the same key will overwrite the old values.

This feature is only applicable for Ad Manager ad requests. AdMob requests currently ignore custom targeting.

setAdChoicesPlacement

@CanIgnoreReturnValue
public @NonNull NativeAdRequest.Builder setAdChoicesPlacement(@NonNull AdChoicesPlacement adChoicesPlacement)

Sets the placement of the AdChoices icon (if available for the returned ad). The default value is AdChoicesPlacement.TOP_RIGHT.

setAdSize

@CanIgnoreReturnValue
public @NonNull NativeAdRequest.Builder setAdSize(@NonNull AdSize adSize)

Sets the AdSize and overwrites any list of ad sizes passed in setAdSizes.

This feature is available to Ad Manager publishers only. For more information, see mix banner and native ad requests. This method impacts banner ads only.

setAdSizes

@CanIgnoreReturnValue
public @NonNull NativeAdRequest.Builder setAdSizes(@NonNull List<@NonNull AdSize> adSizes)

Sets a list of valid AdSizes and overwrites the ad size passed in setAdSize with the first size in the list.

This feature is available to Ad Manager publishers only. See mix banner and native ad requests for more information. This method impacts banner ads only.

setContentUrl

@CanIgnoreReturnValue
public final @NonNull NativeAdRequest.Builder setContentUrl(@NonNull String contentUrl)

Sets the content URL for a web site whose content matches the app's primary content. This web site content is used for targeting and brand safety purposes.

Throws
kotlin.IllegalArgumentException

If contentUrl is empty.

setCustomFormatIds

@CanIgnoreReturnValue
public @NonNull NativeAdRequest.Builder setCustomFormatIds(@NonNull List<@NonNull String> customFormatIds)

Sets custom native ad format IDs defined in the Ad Manager UI.

This feature is available to Ad Manager publishers only.

setGoogleExtrasBundle

@CanIgnoreReturnValue
public final @NonNull NativeAdRequest.Builder setGoogleExtrasBundle(@NonNull Bundle extraBundle)

Set extra parameters to pass to AdMob or Ad Manager. Calling this a second time will overwrite the old values.

Parameters
@NonNull Bundle extraBundle

A Bundle of extra information to pass to AdMob or Ad Manager.

setManualImpressionEnabled

public @NonNull NativeAdRequest.Builder setManualImpressionEnabled(boolean enabled)

Indicates whether you intend to record impressions manually for the BannerAd. Use BannerAd.recordManualImpression to record impressions manually.

setMediaAspectRatio

@CanIgnoreReturnValue
public @NonNull NativeAdRequest.Builder setMediaAspectRatio(
    @NonNull NativeAd.NativeMediaAspectRatio mediaAspectRatio
)

Sets the media aspect ratio.

setNeighboringContentUrls

@CanIgnoreReturnValue
public final @NonNull NativeAdRequest.Builder setNeighboringContentUrls(
    @NonNull Set<@NonNull String> neighboringContentUrls
)

Sets URLs representing web content near an ad. Promotes brand safety and allows displayed ads to have an app level rating (MA, T, PG, etc) that is more appropriate to neighboring content.

Parameters
@NonNull Set<@NonNull String> neighboringContentUrls

The set of neighboring content URLs to be attached to the existing neighboring content URLs.

setPlacementId

@CanIgnoreReturnValue
public @NonNull NativeAdRequest.Builder setPlacementId(long placementId)

Sets a default placement ID for the loaded ad.

Parameters
long placementId

A long integer provided by the AdMob UI for the configured placement.

setPublisherProvidedId

@CanIgnoreReturnValue
public final @NonNull NativeAdRequest.Builder setPublisherProvidedId(@NonNull String publisherProvidedId)

Sets an identifier for use in frequency capping, audience segmentation and targeting, sequential ad rotation, and other audience-based ad delivery controls across devices.

This feature is only applicable for Ad Manager ad requests. Any ID will be ignored on AdMob requests.

setRequestAgent

@CanIgnoreReturnValue
public final @NonNull NativeAdRequest.Builder setRequestAgent(@NonNull String requestAgent)

Sets the request agent string to identify the ad request's origin. Third party libraries that implement the Mobile Ads SDK on behalf of publishers should call this method to denote the platform from which the ad request originated.

setVideoOptions

@CanIgnoreReturnValue
public @NonNull NativeAdRequest.Builder setVideoOptions(@NonNull VideoOptions videoOptions)

Sets the VideoOptions for this request.

Protected methods

getAdSourceExtrasBundles

protected final @NonNull Map<@NonNull String, @NonNull BundlegetAdSourceExtrasBundles()

getAdUnitId

protected final String getAdUnitId()

The ad unit ID.

getCategoryExclusions

protected final @NonNull Set<@NonNull StringgetCategoryExclusions()

getContentUrl

protected final String getContentUrl()

getCustomTargeting

protected final @NonNull Map<@NonNull String, @NonNull StringgetCustomTargeting()

getGoogleExtrasBundle

protected final @NonNull Bundle getGoogleExtrasBundle()

getKeywords

protected final @NonNull HashSet<@NonNull StringgetKeywords()

getNeighboringContentUrls

protected final @NonNull HashSet<@NonNull StringgetNeighboringContentUrls()

getPlacementId

protected final long getPlacementId()

getPublisherProvidedId

protected final String getPublisherProvidedId()

getRequestAgent

protected final String getRequestAgent()

self

protected @NonNull NativeAdRequest.Builder self()

setAdUnitId

protected final void setAdUnitId(String adUnitId)

The ad unit ID.