AdRequest.Builder | Android Developers

Quicknav Quicknav
Links

- Google Play Developer Console
- Android Developers Blog
- About Android

Android Sites

- Android.com
- Android Developers
- Android Open Source Project

Language
close

- - About
  - Wear
  - TV
  - Auto
- - Get Started
  - Devices
  - Style
  - Patterns
  - Building Blocks
  - Downloads
  - Videos
- - Training
  - API Guides
  - Reference
  - Tools
  - Google Services
  - Samples
- - Google Play
  - Essentials
  - Get Users
  - Engage & Retain
  - Monetize
  - Analyze
  - Tools & Reference
  - Developer Stories

## Results

Loading...
Summary: Ctors | Methods | Inherited Methods | [Expand All]
public static final class

# AdRequest.Builder

extends Object

java.lang.Object
↳ | com.google.android.gms.ads.AdRequest.Builder

## Class Overview

Builds an `AdRequest`.

## Summary

Public Constructors
| AdRequest.Builder()

Public Methods
AdRequest.Builder | addCustomEventExtrasBundle(Class<? extends CustomEvent> adapterClass, Bundle customEventExtras) Add extra parameters to pass to a specific custom event adapter.
AdRequest.Builder | addKeyword(String keyword) Add a keyword for targeting purposes.
AdRequest.Builder | addNetworkExtras(NetworkExtras networkExtras) Add extra parameters to pass to a specific ad network adapter.
AdRequest.Builder | addNetworkExtrasBundle(Class<? extends MediationAdapter> adapterClass, Bundle networkExtras) Add extra parameters to pass to a specific ad network adapter.
AdRequest.Builder | addTestDevice(String deviceId) Causes a device to receive test ads.
AdRequest | build() Constructs an `AdRequest` with the specified attributes.
AdRequest.Builder | setBirthday(Date birthday) Sets the user's birthday for targeting purposes.
AdRequest.Builder | setContentUrl(String contentUrl) Sets the content URL for targeting purposes.
AdRequest.Builder | setGender(int gender) Sets the user's gender for targeting purposes.
AdRequest.Builder | setLocation(Location location) Sets the user's location for targeting purposes.
AdRequest.Builder | setRequestAgent(String requestAgent) Sets the request agent string to identify the ad request's origin.
AdRequest.Builder | tagForChildDirectedTreatment(boolean tagForChildDirectedTreatment) This method allows you to specify whether you would like your app to be treated as child-directed for purposes of the Children’s Online Privacy Protection Act (COPPA) - http://business.ftc.gov/privacy-and-security/childrens-privacy.

[Expand] Inherited Methods
From class java.lang.Object
Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)

## Public Constructors

#### public AdRequest.Builder ()

## Public Methods

#### public AdRequest.Builder addCustomEventExtrasBundle (Class<? extends CustomEvent> adapterClass, Bundle customEventExtras)

Add extra parameters to pass to a specific custom event adapter.

##### Parameters

adapterClass | The `Class` of the custom event adapter for which you are providing extras.
customEventExtras | A `Bundle` of extra information to pass to a custom event adapter.

#### public AdRequest.Builder addKeyword (String keyword)

Add a keyword for targeting purposes.

#### public AdRequest.Builder addNetworkExtras (NetworkExtras networkExtras)

Add extra parameters to pass to a specific ad network adapter. `networkExtras` should be an instance of `com.google.ads.mediation.NetworkExtras`, which is provided by ad network adapters.

#### public AdRequest.Builder addNetworkExtrasBundle (Class<? extends MediationAdapter> adapterClass, Bundle networkExtras)

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

##### Parameters

adapterClass | The `Class` of the adapter for the network for which you are providing extras.
networkExtras | A `Bundle` of extra information to pass to a mediation adapter.

#### public AdRequest.Builder addTestDevice (String deviceId)

Causes a device to receive test ads. The `deviceId` can be obtained by viewing the logcat output after creating a new ad.

#### public AdRequest build ()

Constructs an `AdRequest` with the specified attributes.

#### public AdRequest.Builder setBirthday (Date birthday)

Sets the user's birthday for targeting purposes.

#### public AdRequest.Builder setContentUrl (String contentUrl)

Sets the content URL for targeting purposes.

##### Throws

NullPointerException | If contentUrl is {code null}.
IllegalArgumentException | If contentUrl is empty, or if its length exceeds 512.

#### public AdRequest.Builder setGender (int gender)

Sets the user's gender for targeting purposes. This should be `GENDER_MALE`, `GENDER_FEMALE`, or `GENDER_UNKNOWN`.

#### public AdRequest.Builder setLocation (Location location)

Sets the user's location for targeting purposes.

#### public AdRequest.Builder setRequestAgent (String requestAgent)

Sets the request agent string to identify the ad request's origin. Third party libraries that reference the Mobile Ads SDK should call this method to denote the platform from which the ad request originated. For example, if a third party ad network called "CoolAds network" mediates requests to the Mobile Ads SDK, it should call this method with "CoolAds".

#### public AdRequest.Builder tagForChildDirectedTreatment (boolean tagForChildDirectedTreatment)

This method allows you to specify whether you would like your app to be treated as child-directed for purposes of the Children’s Online Privacy Protection Act (COPPA) - http://business.ftc.gov/privacy-and-security/childrens-privacy.

If you set this method to `true`, you will indicate that your app should be treated as child-directed for purposes of the Children’s Online Privacy Protection Act (COPPA).

If you set this method to `false`, you will indicate that your app should not be treated as child-directed for purposes of the Children’s Online Privacy Protection Act (COPPA).

If you do not set this method, ad requests will include no indication of how you would like your app treated with respect to COPPA.

By setting this method, you certify that this notification is accurate and you are authorized to act on behalf of the owner of the app. You understand that abuse of this setting may result in termination of your Google account.

Note: it may take some time for this designation to be fully implemented in applicable Google services.

This designation will only apply to ad requests for which you have set this method.

##### Parameters

tagForChildDirectedTreatment | Set to `true` to indicate that your app should be treated as child-directed. Set to `false` to indicate that your app should not be treated as child-directed.