Google is committed to advancing racial equity for Black communities. See how.

AdManagerAdView

public final class AdManagerAdView extends BaseAdView

The View to 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 AdManagerAdView from code.
AdManagerAdView(Context context, AttributeSet attrs)
Constructs an AdManagerAdView from an XML layout.
AdManagerAdView(Context context, AttributeSet attrs, int defStyle)
Constructs an AdManagerAdView from an XML layout.

Public Method Summary

AdSize[]
getAdSizes()
Returns the ad sizes supported by this AdManagerAdView.
AppEventListener
VideoController
getVideoController()
Returns the VideoController for this ad view.
VideoOptions
getVideoOptions()
Returns the VideoOptions 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 the VideoOptions for this ad view.

Inherited Method Summary

XML Attributes

AdsAttrs_adSizes

AdsAttrs_adUnitId

    Public Constructors

    public AdManagerAdView (Context context)

    Constructs an AdManagerAdView from code.

    Parameters
    context The Context the AdManagerAdView is running in.

    public AdManagerAdView (Context context, AttributeSet attrs)

    Constructs an AdManagerAdView from an XML layout.

    public AdManagerAdView (Context context, AttributeSet attrs, int defStyle)

    Constructs an AdManagerAdView from an XML layout.

    Public Methods

    public AdSize[] getAdSizes ()

    Returns the ad sizes supported by this AdManagerAdView. See BaseAdView.getAdSize() for the size of the currently displayed banner ad.

    public AppEventListener getAppEventListener ()

    Returns the AppEventListener for this AdManagerAdView.

    public VideoController getVideoController ()

    Returns the VideoController for this ad view.

    public VideoOptions getVideoOptions ()

    Returns the VideoOptions for this ad view.

    public void loadAd (AdManagerAdRequest adManagerAdRequest)

    Loads an ad.

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

    public void recordManualImpression ()

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

    public void setAdSizes (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 call BaseAdView.getAdSize() during the AdListener.onAdLoaded() callback and change the layout according to the size of the ad that was loaded. If multiple ad sizes are specified, the AdManagerAdView 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 If adSizes is null or empty.

    public void setAppEventListener (AppEventListener appEventListener)

    Sets an AppEventListener for this AdManagerAdView.

    public void setManualImpressionsEnabled (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 void setVideoOptions (VideoOptions videoOptions)

    Sets the VideoOptions for this ad view.

    Attribute Name
    AdsAttrs_adSizes
    AdsAttrs_adUnitId