Banner

Follow

Before You Start

Before integrating ads unit in your app, you must:

Banner

Banners are rectangular, system-initiated ads that served in a designated area around your live app content.

BannerAd Formats:

Image text

Step 1. Init Banner Ad

The AdTiming SDK fires several events to inform you of Banner Ad activity. To display Banner Ads, one needs to create a brand new BannerAd object, setup its listeners and load the ads.

The following snippet demonstrates how to use the BannerAd class to create BannerAd objects and implement the BannerAdListener interface to receive Native Ad events. The SDK will notify the Listener of all possible events listed below:

import com.aiming.mdt.banner.BannerAd;
import com.aiming.mdt.banner.BannerAdListener
...
BannerAd bannerAd = new BannerAd(activity, placementId,new BannerAdListener() {

      /** 
       * Invoked when Banner Ad are available. 
       * You can then show the video by calling bannerAd.showAd(). 
       */
      @Override
      public void onAdReady(View view) {
          // bannerAd is load success
      }

      /** 
       * Invoked when the end user clicked on the Banner Ad 
       */
      @Override
      public void onAdClicked() {
         // bannerAd click
      }

      /** 
       * Invoked when the call to load a Banner Ad has failed 
       * String error contains the reason for the failure. 
      */
      @Override
      public void onAdFailed(String error) {
         // bannerAd fail
      }});            

 

Step 2. Load BannerAd

Invoke loadAd method to request and cache the Banner Ad before it is available for display to users. It is strongly recommended to invoke this method a short while before the ad is to be shown.  

bannerAd.loadAd()

 Notes

  • The loadAd method could be called multiple times at any time, but we do not recommend continuous requests for a short period of time. Many requests in a short period of time have no added value because the opportunities of available for inventory is unlikely at this time. 
  • !Warning: Attempting to load a new ad from the onAdFailed() methods is strongly discouraged. If you must load an ad from onAdFailed() ensure to limit ad load retries to avoid continuous failed ad requests in situations such as limited network connectivity.

 

Step 3. Show BannerAd

After the Interactive Ad is successfully loaded by calling the loadAd in Step 2, you will be notified when the ad is ready to be shown through the onAdReady callback which will inform you the avaliability of ad inventory. 

Once you receive the onAdReady callback, you  can use code belows to show and serve the Banner Ad to your users.

 private RelativeLayout adParent;
 ...
 adParent = this.findViewById(R.id.native_ad_container);
 ...

 @Override
 public void onAdReady(View view) {
    // bannerAd is loaded successfully
    if (null != view.getParent()) {
        ((ViewGroup) view.getParent()).removeView(view);
    }
    adParent.removeAllViews();
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    adParent.addView(view, layoutParams);
}

■ R.id.native_ad_container code as following:

<RelativeLayout
   android:id="@+id/native_ad_container"
   android:layout_width="match_parent"
   android:layout_height="wrap_content">

</RelativeLayout>

 

Step 4. Destory BannerAd Object

It is recommended to invoke destroy method to release BannerAd object when the Activity be destroyed.

@Override
public void onDestroy() {
if (bannerAd != null) {
bannerAd.destroy();
}
super.onDestroy();
}
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.