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_AD_STRING The ad string is invalid.
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 request ID in the ad string is not found.
int MAX_CONTENT_URL_LENGTH The maximum content URL length.

Public Method Summary

String
getAdString()
Gets the ad string.
String
getContentUrl()
Returns the content URL targeting information.
<T extends CustomEvent> Bundle
getCustomEventExtrasBundle(Class<T> adapterClass)
This method is deprecated. Use getNetworkExtrasBundle(Class) instead.
Set<String>
getKeywords()
Returns targeting information keywords.
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.
String
getRequestAgent()
Returns the request agent string to identify ad request's origin.
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_AD_STRING

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

Constant Value: 11

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 request ID in the ad string is not found.

Constant Value: 10

public static final int MAX_CONTENT_URL_LENGTH

The maximum content URL length.

Constant Value: 512

Public Methods

public String getAdString ()

Gets the ad string.

public String getContentUrl ()

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

public Bundle getCustomEventExtrasBundle (Class<T> adapterClass)

This method is deprecated.
Use getNetworkExtrasBundle(Class) instead.

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 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 String getRequestAgent ()

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

public boolean isTestDevice (Context context)

Returns true if this device will receive test ads.