AdRequest

class AdRequest

Known direct subclasses
AdManagerAdRequest

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


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

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

Summary

Nested types

Builds an AdRequest.

Constants

const String!
DEVICE_ID_EMULATOR = "B3EEABB8EE11C2BE770B684D95219ECB"

The deviceId for emulators to be used with setTestDeviceIds.

const Int

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

const Int

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

const Int

The ad string is invalid.

const Int

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

const Int

The mediation adapter did not fill the ad request.

const Int

The ad request was unsuccessful due to network connectivity.

const Int

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

const Int

The request ID in the ad string is not found.

const Int

The maximum content URL length.

Public functions

String?

Gets the ad string.

String!

Returns the content URL targeting information.

Bundle?
<T : CustomEvent?> getCustomEventExtrasBundle(adapterClass: Class<T!>!)

This function is deprecated.

Use getNetworkExtrasBundle instead.

(Mutable)Set<String!>!

Returns targeting information keywords.

(Mutable)List<String!>!

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

Bundle?
<T : MediationExtrasReceiver?> getNetworkExtrasBundle(
    adapterClass: Class<T!>!
)

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

String!

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

Boolean
isTestDevice(context: Context!)

Returns true if this device will receive test ads.

Constants

DEVICE_ID_EMULATOR

const val DEVICE_ID_EMULATOR = "B3EEABB8EE11C2BE770B684D95219ECB": String!

The deviceId for emulators to be used with setTestDeviceIds.

ERROR_CODE_APP_ID_MISSING

const val ERROR_CODE_APP_ID_MISSING = 8: Int

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

ERROR_CODE_INTERNAL_ERROR

const val ERROR_CODE_INTERNAL_ERROR = 0: Int

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

ERROR_CODE_INVALID_AD_STRING

const val ERROR_CODE_INVALID_AD_STRING = 11: Int

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

ERROR_CODE_INVALID_REQUEST

const val ERROR_CODE_INVALID_REQUEST = 1: Int

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

ERROR_CODE_MEDIATION_NO_FILL

const val ERROR_CODE_MEDIATION_NO_FILL = 9: Int

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

ERROR_CODE_NETWORK_ERROR

const val ERROR_CODE_NETWORK_ERROR = 2: Int

The ad request was unsuccessful due to network connectivity.

ERROR_CODE_NO_FILL

const val ERROR_CODE_NO_FILL = 3: Int

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

ERROR_CODE_REQUEST_ID_MISMATCH

const val ERROR_CODE_REQUEST_ID_MISMATCH = 10: Int

The request ID in the ad string is not found.

MAX_CONTENT_URL_LENGTH

const val MAX_CONTENT_URL_LENGTH = 512: Int

The maximum content URL length.

Public functions

getAdString

fun getAdString(): String?

Gets the ad string.

getContentUrl

fun getContentUrl(): String!

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

getCustomEventExtrasBundle

fun <T : CustomEvent?> getCustomEventExtrasBundle(adapterClass: Class<T!>!): Bundle?

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

getKeywords

fun getKeywords(): (Mutable)Set<String!>!

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

getNeighboringContentUrls

fun getNeighboringContentUrls(): (Mutable)List<String!>!

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

getNetworkExtrasBundle

fun <T : MediationExtrasReceiver?> getNetworkExtrasBundle(
    adapterClass: Class<T!>!
): Bundle?

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

getRequestAgent

fun getRequestAgent(): String!

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

isTestDevice

fun isTestDevice(context: Context!): Boolean

Returns true if this device will receive test ads.