Google is committed to advancing racial equity for Black communities. See how.

AdRequest

public class AdRequest extends Object
Known Direct Subclasses

An AdRequest contains targeting information used to fetch an ad. Ad requests are created using AdRequest.Builder.

Publishers using Ad Manager or Search Ads for Apps should use AdManagerAdRequest or DynamicHeightSearchAdRequest, respectively.

Nested Class Summary

class AdRequest.Builder Builds an AdRequest

Constant Summary

String DEVICE_ID_EMULATOR The deviceId for emulators to be used with RequestConfiguration.Builder.setTestDeviceIds(List).
int ERROR_CODE_APP_ID_MISSING The ad request was not made due to a missing app ID.
int ERROR_CODE_INTERNAL_ERROR Something happened internally; for instance, an invalid response was received from the ad server.
int ERROR_CODE_INVALID_REQUEST The ad request was invalid; for instance, the ad unit ID was incorrect.
int ERROR_CODE_MEDIATION_NO_FILL The mediation adapter did not fill the ad request.
int ERROR_CODE_NETWORK_ERROR The ad request was unsuccessful due to network connectivity.
int ERROR_CODE_NO_FILL The ad request was successful, but no ad was returned due to lack of ad inventory.
int ERROR_CODE_REQUEST_ID_MISMATCH The AdInfo object inside the ad request has mismatching request IDs.
int GENDER_FEMALE Female gender.
int GENDER_MALE Male gender.
int GENDER_UNKNOWN Unknown gender.
int MAX_CONTENT_URL_LENGTH The maximum content URL length.

Public Method Summary

String
getContentUrl()
Returns the content URL targeting information.
<T extends CustomEvent> Bundle
getCustomEventExtrasBundle(Class<T> adapterClass)
Returns extra parameters to pass to a specific custom event adapter.
Set<String>
getKeywords()
Returns targeting information keywords.
Location
getLocation()
Returns the user's location targeting information.
List<String>
getNeighboringContentUrls()
Returns the list of neighboring content URLs or an empty list if no URLs were set.
<T extends MediationExtrasReceiver> Bundle
getNetworkExtrasBundle(Class<T> adapterClass)
Returns extra parameters to pass to a specific ad network adapter.
boolean
isTestDevice(Context context)
Returns true if this device will receive test ads.

Inherited Method Summary

Constants

public static final String DEVICE_ID_EMULATOR

The deviceId for emulators to be used with RequestConfiguration.Builder.setTestDeviceIds(List).

Constant Value: "B3EEABB8EE11C2BE770B684D95219ECB"

public static final int ERROR_CODE_APP_ID_MISSING

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

Constant Value: 8

public static final int ERROR_CODE_INTERNAL_ERROR

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

Constant Value: 0

public static final int ERROR_CODE_INVALID_REQUEST

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

Constant Value: 1

public static final int ERROR_CODE_MEDIATION_NO_FILL

The mediation adapter did not fill the ad request. If this error is returned from AdError.getCode(), check AdError.getCause() for the underlying cause.

Constant Value: 9

public static final int ERROR_CODE_NETWORK_ERROR

The ad request was unsuccessful due to network connectivity.

Constant Value: 2

public static final int ERROR_CODE_NO_FILL

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

Constant Value: 3

public static final int ERROR_CODE_REQUEST_ID_MISMATCH

The AdInfo object inside the ad request has mismatching request IDs.

Constant Value: 10

public static final int GENDER_FEMALE

Female gender.

Constant Value: 2

public static final int GENDER_MALE

Male gender.

Constant Value: 1

public static final int GENDER_UNKNOWN

Unknown gender.

Constant Value: 0

public static final int MAX_CONTENT_URL_LENGTH

The maximum content URL length.

Constant Value: 512

Public Methods

public String getContentUrl ()

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

public Bundle getCustomEventExtrasBundle (Class<T> adapterClass)

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

public Set<String> getKeywords ()

Returns targeting information keywords. Returns an empty Set if no keywords were added.

public Location getLocation ()

Returns the user's location targeting information. Returns null if the location was not set.

public List<String> getNeighboringContentUrls ()

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

public Bundle getNetworkExtrasBundle (Class<T> adapterClass)

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

public boolean isTestDevice (Context context)

Returns true if this device will receive test ads.