public class AdRequest extends Object
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.Modifier and Type | Class and Description |
---|---|
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.
|
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
AdRequest() |
Modifier and Type | Method and Description |
---|---|
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.
|
public static final String VERSION
public static final String LOGTAG
public static final String TEST_EMULATOR
public AdRequest setGender(AdRequest.Gender gender)
gender
- the gender.public AdRequest.Gender getGender()
@Deprecated public AdRequest setBirthday(String birthday)
setBirthday(Calendar)
or
setBirthday(Date)
.birthday
- the birthday String
in the format of
YYYYMMDD
.public AdRequest setBirthday(Date birthday)
birthday
- the birthday Date
.public AdRequest setBirthday(Calendar calendar)
calendar
- a Calendar
, set to the correct date.public Date getBirthday()
public AdRequest clearBirthday()
@Deprecated public AdRequest setPlusOneOptOut(boolean plusOneOptOut)
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.plusOneOptOut
- true
if the publisher desires to opt out of
showing the +1 widget on ads in their application.@Deprecated public boolean getPlusOneOptOut()
setNetworkExtras(NetworkExtras)
with an instance of
AdMobAdapterExtras
, and the property read there.
Gets the publisher +1 opt out bit.public AdRequest setKeywords(Set<String> keywords)
keywords
- the keywords.addKeyword(String)
public AdRequest addKeyword(String keyword)
keyword
- the keyword to add.setKeywords(Set)
public AdRequest addKeywords(Set<String> keywords)
keywords
- the keywords to add.setKeywords(Set)
public Set<String> getKeywords()
setKeywords(Set)
@Deprecated public AdRequest setExtras(Map<String,Object> extras)
setNetworkExtras(NetworkExtras)
with an instance of
AdMobAdapterExtras
.extras
- the new map of values to send with the ad request.addExtra(String, Object)
@Deprecated public AdRequest addExtra(String key, Object value)
setNetworkExtras(NetworkExtras)
with an instance of
AdMobAdapterExtras
.key
- the key of the extra to add.value
- the value of the extra to add.setExtras(Map)
public AdRequest setNetworkExtras(NetworkExtras extras)
public AdRequest removeNetworkExtras(Class<?> extrasClass)
public <T> T getNetworkExtras(Class<T> extrasClass)
public AdRequest setMediationExtras(Map<String,Object> mediationExtras)
mediationExtras
- the new map of values to send with the ad request.addExtra(String, Object)
public AdRequest addMediationExtra(String key, Object value)
key
- the key of the extra to add.value
- the value of the extra to add.setExtras(Map)
public AdRequest setLocation(Location location)
location
- the Location
.public Location getLocation()
@Deprecated public AdRequest setTesting(boolean testing)
addTestDevice(String)
or
setTestDevices(Set)
instead.testing
- true
if the test ads should be shown on emulators.addTestDevice(String)
,
setTestDevices(Set)
public Map<String,Object> getRequestMap(Context context)
AdRequest
.Map
with all the parameters and their associated keys.public AdRequest addTestDevice(String testDevice)
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
testDevice
- the device ID. Use TEST_EMULATOR
to get test
ads in the emulator.setTestDevices(Set)
public AdRequest setTestDevices(Set<String> testDevices)
testDevices
- the test devices.addTestDevice(String)