com.google.ads
Class AdRequest

java.lang.Object
  extended by com.google.ads.AdRequest

public class AdRequest
extends Object

An AdRequest object contains information about the ad to fetch. The information is primarily for targeting, though parameters can also be set to control ad formats and such. All set and clear methods return the AdRequest, to allow calls to be chained together as a single expression.


Nested Class Summary
static class AdRequest.ErrorCode
          An enumeration of the various types of errors that might occur while fetching an ad.
static class AdRequest.Gender
          The gender of the user for targeting purposes.
 
Field Summary
static String LOGTAG
          The tag the SDK uses for all logging messages.
static String TEST_EMULATOR
          The constant for the emulator's device ID.
static String VERSION
          The current version of the SDK.
 
Constructor Summary
AdRequest()
           
 
Method Summary
 AdRequest addExtra(String key, Object value)
          Deprecated. 
 AdRequest addKeyword(String keyword)
          Adds a keyword.
 AdRequest addKeywords(Set<String> keywords)
          Adds keywords.
 AdRequest addMediationExtra(String key, Object value)
          Adds an extra mediation request parameter.
 AdRequest addTestDevice(String testDevice)
          Causes test ads to be returned to a device.
 AdRequest clearBirthday()
          Clears the user's birthday for targeting purposes.
 Date getBirthday()
          Gets the user's birthday for targeting purposes.
 AdRequest.Gender getGender()
          Gets the user's gender for targeting purposes.
 Set<String> getKeywords()
          Gets keywords.
 Location getLocation()
          Gets the user's location for targeting purposes.
<T> T
getNetworkExtras(Class<T> extrasClass)
          Gets the extras for an ad network.
 boolean getPlusOneOptOut()
          Deprecated. 
 Map<String,Object> getRequestMap(Context context)
          Creates a map from all of the information contained within this AdRequest.
 boolean isTestDevice(Context context)
          Returns true if this device will have test ads returned or false if real ads are returned.
 AdRequest removeNetworkExtras(Class<?> extrasClass)
          Un-sets the extras for an ad network.
 AdRequest setBirthday(Calendar calendar)
          Sets the user's birthday for targeting purposes.
 AdRequest setBirthday(Date birthday)
          Sets the user's birthday for targeting purposes.
 AdRequest setBirthday(String birthday)
          Deprecated. 
 AdRequest setExtras(Map<String,Object> extras)
          Deprecated. 
 AdRequest setGender(AdRequest.Gender gender)
          Sets the user's gender for targeting purposes.
 AdRequest setKeywords(Set<String> keywords)
          Sets the keywords.
 AdRequest setLocation(Location location)
          Sets the user's location for targeting purposes.
 AdRequest setMediationExtras(Map<String,Object> mediationExtras)
          Sets the extra mediation request parameters.
 AdRequest setNetworkExtras(NetworkExtras extras)
          Ad networks may have their additional parameters they accept.
 AdRequest setPlusOneOptOut(boolean plusOneOptOut)
          Deprecated. 
 AdRequest setTestDevices(Set<String> testDevices)
          Sets the test devices.
 AdRequest setTesting(boolean testing)
          Deprecated. 
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
The current version of the SDK.

See Also:
Constant Field Values

LOGTAG

public static final String LOGTAG
The tag the SDK uses for all logging messages.

See Also:
Constant Field Values

TEST_EMULATOR

public static final String TEST_EMULATOR
The constant for the emulator's device ID.

Constructor Detail

AdRequest

public AdRequest()
Method Detail

setGender

public AdRequest setGender(AdRequest.Gender gender)
Sets the user's gender for targeting purposes.

Parameters:
gender - the gender.

getGender

public AdRequest.Gender getGender()
Gets the user's gender for targeting purposes.


setBirthday

@Deprecated
public AdRequest setBirthday(String birthday)
Deprecated. 

This has been deprecated in favor of setBirthday(Calendar) or setBirthday(Date).

Parameters:
birthday - the birthday String in the format of YYYYMMDD.

setBirthday

public AdRequest setBirthday(Date birthday)
Sets the user's birthday for targeting purposes.

Parameters:
birthday - the birthday Date.

setBirthday

public AdRequest setBirthday(Calendar calendar)
Sets the user's birthday for targeting purposes.

Parameters:
calendar - a Calendar, set to the correct date.

getBirthday

public Date getBirthday()
Gets the user's birthday for targeting purposes.


clearBirthday

public AdRequest clearBirthday()
Clears the user's birthday for targeting purposes.


setPlusOneOptOut

@Deprecated
public AdRequest setPlusOneOptOut(boolean plusOneOptOut)
Deprecated. 

This has been deprecated in favor of setNetworkExtras(NetworkExtras) with an instance of AdMobAdapterExtras, and the property set there. Sets the publisher +1 opt out bit. If this bit is set, the ads returned will not contain the +1 widget.

Parameters:
plusOneOptOut - true if the publisher desires to opt out of showing the +1 widget on ads in their application.

getPlusOneOptOut

@Deprecated
public boolean getPlusOneOptOut()
Deprecated. 

This has been deprecated in favor of setNetworkExtras(NetworkExtras) with an instance of AdMobAdapterExtras, and the property read there. Gets the publisher +1 opt out bit.


setKeywords

public AdRequest setKeywords(Set<String> keywords)
Sets the keywords.

Parameters:
keywords - the keywords.
See Also:
addKeyword(String)

addKeyword

public AdRequest addKeyword(String keyword)
Adds a keyword.

Parameters:
keyword - the keyword to add.
See Also:
setKeywords(Set)

addKeywords

public AdRequest addKeywords(Set<String> keywords)
Adds keywords.

Parameters:
keywords - the keywords to add.
See Also:
setKeywords(Set)

getKeywords

public Set<String> getKeywords()
Gets keywords.

See Also:
setKeywords(Set)

setExtras

@Deprecated
public AdRequest setExtras(Map<String,Object> extras)
Deprecated. 

Sets the extra ad request parameters. This has been deprecated in favor of setNetworkExtras(NetworkExtras) with an instance of AdMobAdapterExtras.

Parameters:
extras - the new map of values to send with the ad request.
See Also:
addExtra(String, Object)

addExtra

@Deprecated
public AdRequest addExtra(String key,
                                     Object value)
Deprecated. 

Adds an extra ad request parameter. This has been deprecated in favor of setNetworkExtras(NetworkExtras) with an instance of AdMobAdapterExtras.

Parameters:
key - the key of the extra to add.
value - the value of the extra to add.
See Also:
setExtras(Map)

setNetworkExtras

public AdRequest setNetworkExtras(NetworkExtras extras)
Ad networks may have their additional parameters they accept. To set these extra parameters, create the settings object for that network, fill in the parameters, and set it here. Different networks are required to have different extras types, and there's no crosstalk between them, so duplicate settings need to be set for each ad network you use. All networks have access to the basic settings you've set in this AdRequest (Gender, Birthday, Testing Mode, etc.).


removeNetworkExtras

public AdRequest removeNetworkExtras(Class<?> extrasClass)
Un-sets the extras for an ad network. You must pass the class which represents that network's extras type.


getNetworkExtras

public <T> T getNetworkExtras(Class<T> extrasClass)
Gets the extras for an ad network.


setMediationExtras

public AdRequest setMediationExtras(Map<String,Object> mediationExtras)
Sets the extra mediation request parameters.

Parameters:
mediationExtras - the new map of values to send with the ad request.
See Also:
addExtra(String, Object)

addMediationExtra

public AdRequest addMediationExtra(String key,
                                   Object value)
Adds an extra mediation request parameter.

Parameters:
key - the key of the extra to add.
value - the value of the extra to add.
See Also:
setExtras(Map)

setLocation

public AdRequest setLocation(Location location)
Sets the user's location for targeting purposes.

Parameters:
location - the Location.

getLocation

public Location getLocation()
Gets the user's location for targeting purposes.


setTesting

@Deprecated
public AdRequest setTesting(boolean testing)
Deprecated. 

This method is deprecated. Use addTestDevice(String) or setTestDevices(Set) instead.

Parameters:
testing - true if the test ads should be shown on emulators.
See Also:
addTestDevice(String), setTestDevices(Set)

getRequestMap

public Map<String,Object> getRequestMap(Context context)
Creates a map from all of the information contained within this AdRequest.

Returns:
the Map with all the parameters and their associated keys.

addTestDevice

public AdRequest addTestDevice(String testDevice)
Causes test ads to be returned to a device. Look at logcat while requesting an ad to see how to return test ads to a device. There will be a log message with the code needed to add the current device to the list of test devices. For example:
   adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
   adRequest.addTestDevice("E83D20734F72FB3108F104ABC0FFC738"); // My T-Mobile G1 test phone
 

Parameters:
testDevice - the device ID. Use TEST_EMULATOR to get test ads in the emulator.
See Also:
setTestDevices(Set)

setTestDevices

public AdRequest setTestDevices(Set<String> testDevices)
Sets the test devices.

Parameters:
testDevices - the test devices.
See Also:
addTestDevice(String)

isTestDevice

public boolean isTestDevice(Context context)
Returns true if this device will have test ads returned or false if real ads are returned.

Parameters:
context - the Context used to determine the current device's ID.
Returns:
true if the current device has been enabled for testing.