public class AdView extends RelativeLayout implements Ad
AdView adView = new AdView(context, PLACEMENT_ID, AdSize.BANNER_HEIGHT_50);
addView(adView);
adView.loadAd();
AdView requires android.permission.INTERNET permission to make network requests.
If android.permission.ACCESS_NETWORK_STATE permission is granted, AdView will only
make network requests when network is connected.Modifier and Type | Class and Description |
---|---|
static interface |
AdView.AdViewLoadConfig
Marker interface for an object that represents an ad load config.
|
static interface |
AdView.AdViewLoadConfigBuilder
Builder that allows to configure an ad loading.
|
Ad.LoadAdConfig, Ad.LoadConfigBuilder
Constructor and Description |
---|
AdView(Context context,
java.lang.String placementId,
AdSize adSize)
Constructs an AdView using the given context, placement_id and size.
|
AdView(Context context,
java.lang.String placementId,
java.lang.String bidPayload)
Constructs an AdView using the given context, placement_id and bid payload.
|
Modifier and Type | Method and Description |
---|---|
AdView.AdViewLoadConfigBuilder |
buildLoadAdConfig()
Returns
AdView.AdViewLoadConfigBuilder that allows to specify ad loading parameters. |
void |
destroy()
Destroys the ad control.
|
void |
disableAutoRefresh()
Deprecated.
auto refresh is no longer supported and therefore this method is now deprecated.
|
java.lang.String |
getPlacementId()
Get the placementId for this ad.
|
boolean |
isAdInvalidated()
Indicate whether the ad is still valid.
|
void |
loadAd()
Loads an ad.
|
void |
loadAd(AdView.AdViewLoadConfig loadAdConfig)
Loads an ad.
|
void |
loadAdFromBid(java.lang.String bidPayload)
Loads an ad from the payload supplied with a bid.
|
protected void |
onConfigurationChanged(Configuration newConfig) |
void |
setAdListener(AdListener adListener)
Deprecated.
since 5.6, use
loadAd(AdViewLoadConfig) |
void |
setExtraHints(ExtraHints extraHints) |
public AdView(Context context, java.lang.String placementId, AdSize adSize)
context
- Android contextplacementId
- id of ad placementadSize
- size of the ad controlpublic AdView(Context context, java.lang.String placementId, java.lang.String bidPayload) throws java.lang.Exception
context
- Android contextplacementId
- id of ad placementbidPayload
- the payload supplied with the bidjava.lang.Exception
@Deprecated public void setAdListener(AdListener adListener)
loadAd(AdViewLoadConfig)
adListener
- the listenerpublic void loadAd()
public void loadAd(AdView.AdViewLoadConfig loadAdConfig)
This method always returns immediately. The ad is loaded asynchronously. The control's ad listener will be called when loading finishes or fails.
AdView adView = new AdView(context, PLACEMENT_ID, AdSize.BANNER_HEIGHT_50);
AdViewLoadConfig loadAdConfig = ad.buildLoadAdConfig()
.withBid(bidPayload)
.withAdListener(adListener)
.build();
ad.loadAd(loadAdConfig);
public void loadAdFromBid(java.lang.String bidPayload)
loadAdFromBid
in interface Ad
bidPayload
- The payload supplied with the bidpublic boolean isAdInvalidated()
Ad
isAdInvalidated
in interface Ad
public void setExtraHints(ExtraHints extraHints)
setExtraHints
in interface Ad
public void destroy()
Ad
This method should be called when the hosting activity of the ad control is destroyed.
public java.lang.String getPlacementId()
Ad
getPlacementId
in interface Ad
@Deprecated public void disableAutoRefresh()
protected void onConfigurationChanged(Configuration newConfig)
public AdView.AdViewLoadConfigBuilder buildLoadAdConfig()
AdView.AdViewLoadConfigBuilder
that allows to specify ad loading parameters.
You should call loadAd(AdViewLoadConfig)
after all parameters have been set.