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.


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
 void addExtra(String key, Object value)
          Adds an extra ad request parameter.
 void addKeyword(String keyword)
          Adds a keyword.
 void addTestDevice(String testDevice)
          Causes test ads to be returned to a device.
 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.
 void setBirthday(String birthday)
          Sets the user's birthday for targeting purposes.
 void setExtras(Map<String,Object> extras)
          Sets the extra ad request parameters.
 void setGender(AdRequest.Gender gender)
          Sets the user's gender for targeting purposes.
 void setKeywords(Set<String> keywords)
          Sets the keywords.
 void setLocation(Location location)
          Sets the user's location for targeting purposes.
 void setPlusOneOptOut(boolean plusOneOptOut)
          Sets the publisher +1 opt out bit.
 void setTestDevices(Set<String> testDevices)
          Sets the test devices.
 void 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 void setGender(AdRequest.Gender gender)
Sets the user's gender for targeting purposes.

Parameters:
gender - the gender.

setBirthday

public void setBirthday(String birthday)
Sets the user's birthday for targeting purposes.

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

setPlusOneOptOut

public void setPlusOneOptOut(boolean plusOneOptOut)
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.

setKeywords

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

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

addKeyword

public void addKeyword(String keyword)
Adds a keyword.

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

setExtras

public void setExtras(Map<String,Object> extras)
Sets the extra ad request parameters.

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

addExtra

public void addExtra(String key,
                     Object value)
Adds an extra ad 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 void setLocation(Location location)
Sets the user's location for targeting purposes.

Parameters:
location - the Location.

setTesting

@Deprecated
public void 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 void 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 void 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.