Banner Video Ads Integration for Android

Do go through the steps in our Getting Started Guide to add Media.Net SDK into your project before starting the integration of Banner Ads.

For adding banner ads to your app, following are the steps:

  • Defining ad slot
  • Loading an ad in the slot
  • Setting up listeners

    a. Define a slot for your banner ad in your layout XML.

    The Media.net SDK provides a custom View subclass, MNetView, which handles requesting and loading ads.

    Include this XML block to your activity’s or fragment’s layout.

          <net.media.android.base.pub.view.MNetView
            	android:id="@+id/mnet_view"
            	android:layout_width="wrap_content"
            	android:layout_height="wrap_content"/>
    

    b. Load an ad into the banner slot

          MNetView mnetView = (MNetView)findViewById(R.id.mnet_view);
          mnetView.setAdUnitId("xxxxxxxxxxx");//Enter your Ad Unit ID
          mnetView.setSizes(AdSize.MEDIUM);
          mentView.loadAd();
    

    c. Listen to the ad state :

    MNetView provides a listener interface, AdListener, which can be used to stay informed about the ad lifecycle events. AdListener has the following methods.

         mnetView.addListener(new AdListener() {
            @Override
            // Sent when the ad slot successfully retrieved a Banner ad.
            public void onAdLoaded() {
               //Do your stuff
            }
            @Override
            // Sent when the ad slot has failed to retrieve an ad.
            public void onError(final MNetError error) {
               //Do your stuff
            }
            @Override
            // Sent when the user has tapped on the Banner ad.
            public void onAdClicked() {
               //Do your stuff
            }
            @Override
            // Sent when the user closes the Ad
            public void onAdClosed() {
               //Do your stuff
            }
         });