AdManagerAdView

public final classAdManagerAdViewextendsBaseAdView

TheViewto display banner ads for use with Google Ad Manager. The ad size and ad unit ID must be set prior to calling BaseAdView.loadAd(AdRequest).

Sample code:

public class MyActivity extends Activity {
private AdManagerAdView adManagerAdView;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);

// Create a banner ad. The ad size and ad unit ID must be set before calling loadAd.
adManagerAdView = new AdManagerAdView(this);
adManagerAdView.setAdSize(AdSize.SMART_BANNER);
adManagerAdView.setAdUnitId( "myAdUnitId" );

// Add the AdManagerAdView to the view hierarchy.
layout.addView(adManagerAdView);

// Start loading the ad.
adManagerAdView.loadAd(new AdManagerAdRequest.Builder().build());

setContentView(layout);
}

@Override
public void onResume() {
super.onResume();

// Resume the AdManagerAdView.
adManagerAdView.resume();
}

@Override
public void onPause() {
// Pause the AdManagerAdView.
adManagerAdView.pause();

super.onPause();
}

@Override
public void onDestroy() {
// Destroy the AdManagerAdView.
adManagerAdView.destroy();

super.onDestroy();
}
}

XML Attribute Summary

Inherited XML Attribute Summary

Inherited Constant Summary

Inherited Field Summary

Public Constructor Summary

AdManagerAdView(Context context)
Constructs an AdManagerAdViewfrom code.
AdManagerAdView(Context context,AttributeSet attrs)
Constructs an AdManagerAdViewfrom an XML layout.
AdManagerAdView(Context context,AttributeSet attrs, int defStyle)
Constructs an AdManagerAdViewfrom an XML layout.

Public Method Summary

AdSize[]
getAdSizes()
Returns the ad sizes supported by this AdManagerAdView.
AppEventListener
VideoController
getVideoController()
Returns theVideoController for this ad view.
VideoOptions
getVideoOptions()
Returns theVideoOptions for this ad view.
void
loadAd(AdManagerAdRequest adManagerAdRequest)
Loads an ad.
void
recordManualImpression()
Records a manual impression.
void
setAdSizes(AdSize... adSizes)
Sets the supported sizes of the banner ad.
void
void
setManualImpressionsEnabled(boolean manualImpressionsEnabled)
Indicates whether you intend to record impressions manually for this AdManagerAdView.
void
setVideoOptions(VideoOptions videoOptions)
Sets theVideoOptions for this ad view.

Inherited Method Summary

XML Attributes

AdsAttrs_adSizes

AdsAttrs_adUnitId

    Public Constructors

    publicAdManagerAdView(Context context)

    Constructs anAdManagerAdView from code.

    Parameters
    context TheContext the AdManagerAdViewis running in.

    publicAdManagerAdView(Contextcontext, AttributeSet attrs)

    Constructs anAdManagerAdView from an XML layout.

    publicAdManagerAdView(Contextcontext, AttributeSet attrs, int defStyle)

    Constructs anAdManagerAdView from an XML layout.

    Public Methods

    publicAdSize[] getAdSizes()

    Returns the ad sizes supported by thisAdManagerAdView. SeeBaseAdView.getAdSize() for the size of the currently displayed banner ad.

    publicAppEventListener getAppEventListener()

    Returns theAppEventListener for thisAdManagerAdView.

    publicVideoController getVideoController()

    Returns theVideoController for this ad view.

    publicVideoOptions getVideoOptions()

    Returns theVideoOptions for this ad view.

    public voidloadAd(AdManagerAdRequest adManagerAdRequest)

    Loads an ad.

    Throws
    IllegalStateException If the size of the banner ad or the ad unit ID have not been set.

    public voidrecordManualImpression()

    Records a manual impression. For this method to have any effect, the loaded ad must allow impressions to be recorded manually.

    public voidsetAdSizes(AdSize... adSizes)

    Sets the supported sizes of the banner ad. In most cases, only one ad size will be specified.

    Multiple ad sizes can be specified if your application can appropriately handle multiple ad sizes. For example, your application might callBaseAdView.getAdSize() during theAdListener.onAdLoaded() callback and change the layout according to the size of the ad that was loaded. If multiple ad sizes are specified, theAdManagerAdView will assume the size of the first ad size until an ad is loaded.

    This method also immediately resizes the currently displayed ad, so calling this method after an ad has been loaded is not recommended unless you know for certain that the content of the ad will render correctly in the new ad size. This can be used if an ad needs to be resized after it has been loaded. If more than one ad size is specified, the currently displayed ad will be resized to the first ad size.

    Throws
    IllegalArgumentException IfadSizesisnullor empty.

    public voidsetAppEventListener(AppEventListener appEventListener)

    public voidsetManualImpressionsEnabled(boolean manualImpressionsEnabled)

    Indicates whether you intend to record impressions manually for this AdManagerAdView.Call this method prior to calling BaseAdView.loadAd(AdRequest).Use recordManualImpression()to record impressions manually.

    public voidsetVideoOptions(VideoOptions videoOptions)

    Sets theVideoOptions for this ad view.

    Attribute Name
    AdsAttrs_adSizes
    AdsAttrs_adUnitId