# AdRequest

# AdRequest


```
class AdRequest
```

<br />

Known direct subclasses [AdManagerAdRequest](https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/admanager/AdManagerAdRequest)

|---|---|
| `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/admanager/AdManagerAdRequest` | An `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/admanager/AdManagerAdRequest` contains targeting information used to fetch an ad from Google Ad Manager. |

*** ** * ** ***

An `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest` contains targeting information used to fetch an ad. Ad requests are created using `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest.Builder`.

Publishers using Ad Manager should use `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/admanager/AdManagerAdRequest`.

## Summary

| ### Nested types |
|---|
| `class https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest.Builder : https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AbstractAdRequestBuilder` Builds an `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest`. |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#DEVICE_ID_EMULATOR() = "B3EEABB8EE11C2BE770B684D95219ECB"` The `deviceId` for emulators to be used with `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/RequestConfiguration.Builder#setTestDeviceIds(java.util.List<java.lang.String>)`. |
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#ERROR_CODE_APP_ID_MISSING() = 8` The ad request was not made due to a missing app ID. |
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#ERROR_CODE_INTERNAL_ERROR() = 0` Something happened internally; for instance, an invalid response was received from the ad server. |
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#ERROR_CODE_INVALID_AD_STRING() = 11` The ad string is invalid. |
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#ERROR_CODE_INVALID_REQUEST() = 1` The ad request was invalid; for instance, the ad unit ID was incorrect. |
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#ERROR_CODE_MEDIATION_NO_FILL() = 9` The mediation adapter did not fill the ad request. |
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#ERROR_CODE_NETWORK_ERROR() = 2` The ad request was unsuccessful due to network connectivity. |
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#ERROR_CODE_NO_FILL() = 3` The ad request was successful, but no ad was returned due to lack of ad inventory. |
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#ERROR_CODE_REQUEST_ID_MISMATCH() = 10` The request ID in the ad string is not found. |
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#MAX_CONTENT_URL_LENGTH() = 512` The maximum content URL length. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html?` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#getAdString()()` Gets the ad string. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#getContentUrl()()` Returns the content URL targeting information. |
| `https://developer.android.com/reference/android/os/Bundle.html?` | `<T : https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/mediation/customevent/CustomEvent?> [getCustomEventExtrasBundle](https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#getCustomEventExtrasBundle(java.lang.Class<T>))(adapterClass: https://developer.android.com/reference/java/lang/Class.html<T!>!)` **This function is deprecated.** Use `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#getNetworkExtrasBundle(java.lang.Class<T>)` instead. <br /> |
| `(https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-set/index.html)https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-set/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!>!` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#getKeywords()()` Returns targeting information keywords. |
| `(https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!>!` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#getNeighboringContentUrls()()` Returns the list of neighboring content URLs or an empty list if no URLs were set. |
| `https://developer.android.com/reference/android/os/Bundle.html?` | `<T : https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/mediation/MediationExtrasReceiver?> https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#getNetworkExtrasBundle(java.lang.Class<T>)( adapterClass: https://developer.android.com/reference/java/lang/Class.html<T!>! )` Returns extra parameters to pass to a specific ad network adapter. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#getPlacementId()()` Gets the placement ID set in this `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest` |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#getRequestAgent()()` Returns the request agent string to identify ad request's origin. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#isTestDevice(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html!)` 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 `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/RequestConfiguration.Builder#setTestDeviceIds(java.util.List<java.lang.String>)`.

### 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 `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdError#getCode()`, check `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdError#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](https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#getCustomEventExtrasBundle(java.lang.Class<T>))(adapterClass: Class<T!>!): Bundle?
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Use `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest#getNetworkExtrasBundle(java.lang.Class<T>)` 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.

### getKeywords

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

Returns targeting information keywords. Returns an empty `https://developer.android.com/reference/java/util/Set.html` 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.

### getPlacementId

```
fun getPlacementId(): Long
```

Gets the placement ID set in this `https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/kotlin/com/google/android/gms/ads/AdRequest`

### 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.