PublisherAdView

public final class PublisherAdView extends ViewGroup

The View to display banner ads for use with DoubleClick for Publishers (DFP). The ad size and ad unit ID must be set prior to calling loadAd(PublisherAdRequest).

Sample code:

 public class MyActivity extends Activity {
     private PublisherAdView mPublisherAdView;

     @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.
         mPublisherAdView = new PublisherAdView(this);
         mPublisherAdView.setAdSize(AdSize.SMART_BANNER);
         mPublisherAdView.setAdUnitId("myAdUnitId");

         // Create an ad request.
         PublisherAdRequest.Builder publisherAdRequestBuilder = new PublisherAdRequest.Builder();

         // Optionally populate the ad request builder.
         publisherAdRequestBuilder.addTestDevice(PublisherAdRequest.DEVICE_ID_EMULATOR);

         // Add the PublisherAdView to the view hierarchy.
         layout.addView(mPublisherAdView);

         // Start loading the ad.
         mPublisherAdView.loadAd(PublisherAdRequestBuilder.build());

         setContentView(layout);
     }

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

         // Resume the PublisherAdView.
         mPublisherAdView.resume();
     }

     @Override
     public void onPause() {
         // Pause the PublisherAdView.
         mPublisherAdView.pause();

         super.onPause();
     }

     @Override
     public void onDestroy() {
         // Destroy the PublisherAdView.
         mPublisherAdView.destroy();

         super.onDestroy();
     }
 }

XML Attribute Summary

Attribute Name AdsAttrs_adSizes AdsAttrs_adUnitId

Inherited Constant Summary

Inherited Field Summary

Public Constructor Summary

PublisherAdView(Context context)
Construct an PublisherAdView from code.
PublisherAdView(Context context, AttributeSet attrs)
Construct a PublisherAdView from an XML layout.
PublisherAdView(Context context, AttributeSet attrs, int defStyle)
Construct an PublisherAdView from an XML layout.

Public Method Summary

void
destroy()
Destroy the PublisherAdView.
AdListener
getAdListener()
Returns the AdListener for this PublisherAdView.
AdSize
getAdSize()
Returns the size of the currently displayed banner ad.
AdSize[]
getAdSizes()
Returns the ad sizes supported by this PublisherAdView.
String
getAdUnitId()
Returns the ad unit ID.
AppEventListener
String
getMediationAdapterClassName()
Returns the mediation adapter class name.
OnCustomRenderedAdLoadedListener
VideoController
getVideoController()
Return the VideoController for this ad view.
VideoOptions
getVideoOptions()
Return the VideoOptions for this ad view.
boolean
isLoading()
Returns true if the ad is loading.
void
loadAd(PublisherAdRequest publisherAdRequest)
Start loading the ad on a background thread.
void
pause()
Pause any extra processing associated with this PublisherAdView.
void
recordManualImpression()
Record a manual impression.
void
resume()
Resume a PublisherAdView after a previous call to pause().
void
setAdListener(AdListener adListener)
Sets an AdListener for this PublisherAdView.
void
setAdSizes(AdSize... adSizes)
Sets the supported sizes of the banner ad.
void
setAdUnitId(String adUnitId)
Sets the ad unit ID.
void
void
setCorrelator(Correlator correlator)
Attach a Correlator to this PublisherAdView.
void
setManualImpressionsEnabled(boolean manualImpressionsEnabled)
Enables manual impression reporting for DFP reservations.
void
void
setVideoOptions(VideoOptions videoOptions)
Set the VideoOptions for this ad view.

Protected Method Summary

void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Inherited Method Summary