AdRequest

Kotlin|Java

public classAdRequest

Known direct subclasses
AdManagerAdRequest

AnAdManagerAdRequest contains targeting information used to fetch an ad from Google Ad Manager.


AnAdRequest contains targeting information used to fetch an ad. Ad requests are created usingAdRequest.Builder.

Publishers using Ad Manager should usecom.google.android.gms.ads.admanager.AdManagerAdRequest.

Summary

Nested types

Builds anAdRequest.

Constants

static finalString
DEVICE_ID_EMULATOR = "B3EEABB8EE11C2BE770B684D95219ECB"

ThedeviceId for emulators to be used withsetTestDeviceIds.

static final int

The ad request was not made due to a missing app ID.

static final int

Something happened internally; for instance, an invalid response was received from the ad server.

static final int

The ad string is invalid.

static final int

The ad request was invalid; for instance, the ad unit ID was incorrect.

static final int

The mediation adapter did not fill the ad request.

static final int

The ad request was unsuccessful due to network connectivity.

static final int

The ad request was successful, but no ad was returned due to lack of ad inventory.

static final int

The request ID in the ad string is not found.

static final int

The maximum content URL length.

Public methods

@NullableString

Gets the ad string.

String

Returns the content URL targeting information.

@NullableBundle
<T extends CustomEvent>getCustomEventExtrasBundle(Class<T> adapterClass)

This method is deprecated.

UsegetNetworkExtrasBundle instead.

Set<String>

Returns targeting information keywords.

List<String>

Returns the list of neighboring content URLs or an empty list if no URLs were set.

@NullableBundle
<T extends MediationExtrasReceiver>getNetworkExtrasBundle(
    Class<T> adapterClass
)

Returns extra parameters to pass to a specific ad network adapter.

long

Gets the placement ID set in thisAdRequest

String

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

boolean

Returnstrue if this device will receive test ads.

Constants

DEVICE_ID_EMULATOR

public static final String DEVICE_ID_EMULATOR = "B3EEABB8EE11C2BE770B684D95219ECB"

ThedeviceId for emulators to be used withsetTestDeviceIds.

ERROR_CODE_APP_ID_MISSING

public static final int ERROR_CODE_APP_ID_MISSING = 8

The ad request was not made due to a missing app ID.

ERROR_CODE_INTERNAL_ERROR

public static final int ERROR_CODE_INTERNAL_ERROR = 0

Something happened internally; for instance, an invalid response was received from the ad server.

ERROR_CODE_INVALID_AD_STRING

public static final int ERROR_CODE_INVALID_AD_STRING = 11

The ad string is invalid. For example, there is no request ID in the ad string.

ERROR_CODE_INVALID_REQUEST

public static final int ERROR_CODE_INVALID_REQUEST = 1

The ad request was invalid; for instance, the ad unit ID was incorrect.

ERROR_CODE_MEDIATION_NO_FILL

public static final int ERROR_CODE_MEDIATION_NO_FILL = 9

The mediation adapter did not fill the ad request. If this error is returned fromgetCode, checkgetCause for the underlying cause.

ERROR_CODE_NETWORK_ERROR

public static final int ERROR_CODE_NETWORK_ERROR = 2

The ad request was unsuccessful due to network connectivity.

ERROR_CODE_NO_FILL

public static final int ERROR_CODE_NO_FILL = 3

The ad request was successful, but no ad was returned due to lack of ad inventory.

ERROR_CODE_REQUEST_ID_MISMATCH

public static final int ERROR_CODE_REQUEST_ID_MISMATCH = 10

The request ID in the ad string is not found.

MAX_CONTENT_URL_LENGTH

public static final int MAX_CONTENT_URL_LENGTH = 512

The maximum content URL length.

Public methods

getAdString

public @NullableString getAdString()

Gets the ad string.

getContentUrl

public String getContentUrl()

Returns the content URL targeting information. Returnsnull if the contentUrl was not set.

getCustomEventExtrasBundle

public @NullableBundle <T extends CustomEvent>getCustomEventExtrasBundle(Class<T> adapterClass)
This method is deprecated.

UsegetNetworkExtrasBundle instead.

Returns extra parameters to pass to a specific custom event adapter. Returnsnull if no custom event extras of the provided type were set.

getKeywords

public Set<StringgetKeywords()

Returns targeting information keywords. Returns an emptySet if no keywords were added.

getNeighboringContentUrls

public List<StringgetNeighboringContentUrls()

Returns the list of neighboring content URLs or an empty list if no URLs were set.

getNetworkExtrasBundle

public @NullableBundle <T extends MediationExtrasReceiver>getNetworkExtrasBundle(
    Class<T> adapterClass
)

Returns extra parameters to pass to a specific ad network adapter. Returnsnull if no network extras of the provided type were set.

getPlacementId

public long getPlacementId()

Gets the placement ID set in thisAdRequest

getRequestAgent

public String getRequestAgent()

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

isTestDevice

public boolean isTestDevice(Context context)

Returnstrue if this device will receive test ads.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-20 UTC.