public class AdView extends RelativeLayout implements Ad
AdView can be declared and added to view:
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.
|
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.
|
protected void |
onConfigurationChanged(Configuration newConfig) |
void |
setExtraHints(ExtraHints extraHints)
Deprecated.
|
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
public void loadAd()
If the AdView is configured to refresh, this will start the refreshing. There is no need to call this method multiple times.
If the AdView is not configured to refresh automatically, it can be refreshed by calling this method again. Each subsequent call should be at least 30 seconds apart.
This method always returns immediately. The ad is loaded asynchronously. If available, the ad listener will be called when loading finishes or fails.
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 boolean isAdInvalidated()
Ad
isAdInvalidated
in interface Ad
@Deprecated 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
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.