Banner Integration for Android

Banners are rectangular, system-initiated ads that can be either static or animated that are served in a designated area around your live app content.

Before You Start

Make sure that you have correctly integrated the ironSource SDK into your application. Integration is outlined here.

Step 1. Create Banner Layout 

First, you’ll need to create a Banner view to configure the Banner.

  • Initiate the Banner view by calling this method (in this example it’s the BANNER banner size):
    IronSourceBannerLayout banner = IronSource.createBanner(Activity, ISBannerSize.BANNER);
    

    See table below for details about our supported standard banner sizes:

    ISBannerSize Description Dimensions in dp (WxH)
    BANNER Standard Banner 320 x 50
    LARGE Large Banner 320 x 90
    RECTANGLE Medium Rectangular Banner 300 x 250
    SMART Smart Banner
    (Adjusted for both mobile and tablet)
    If (screen height ≤ 720) 320 x 50
    If (screen height > 720) 728 x 90
  • Another option is initiating the banner with Custom size, using this signature (WxH in dp):
    IronSourceBannerLayout banner = IronSource.createBanner(Activity, new ISBannerSize(320, 50));

     

Create and load a banner ad:

Here’s an example that initiates and loads a banner in the onCreate() method of an Activity:

/** Called when the activity is first created. */
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        // YOUR OTHER CODE //
        // YOUR OTHER CODE //
        // YOUR OTHER CODE //
        IronSource.init(this, "YOUR_APP_KEY", IronSource.AD_UNIT.BANNER);
 
        final FrameLayout bannerContainer = findViewById(R.id.bannerContainer);
        IronSourceBannerLayout banner = IronSource.createBanner(this, ISBannerSize.BANNER);
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.WRAP_CONTENT);
        bannerContainer.addView(banner, 0, layoutParams);
 
        banner.setBannerListener(new BannerListener() {
                @Override
                public void onBannerAdLoaded() {
                // Called after a banner ad has been successfully loaded
                }
 
                @Override
                public void onBannerAdLoadFailed(IronSourceError error) {
                // Called after a banner has attempted to load an ad but failed.
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            bannerContainer.removeAllViews();
                        }
                    });
                }
 
                @Override
                public void onBannerAdClicked() {
                // Called after a banner has been clicked.
                }
 
                @Override
                public void onBannerAdScreenPresented() {
                // Called when a banner is about to present a full screen content.
                }
 
                @Override
                public void onBannerAdScreenDismissed() {
                // Called after a full screen content has been dismissed
                }
 
                @Override
                public void onBannerAdLeftApplication() {
                // Called when a user would be taken out of the application context.
                }
            });
 
        IronSource.loadBanner(banner);
        // YOUR OTHER CODE //
        // YOUR OTHER CODE //
        // YOUR OTHER CODE //
    }

For this example to work you are going to need a .xml file, to describe this bannerContainer:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:tools="http://schemas.android.com/tools"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       tools:context=".MainActivity">
 
    <FrameLayout
       android:id="@+id/bannerContainer"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_gravity="bottom"
       android:visibility="visible" />
 
</FrameLayout>

Step 2. Implement the Listener

Next, implement the Banner Listener in your code. The ironSource SDK fires several callbacks to inform you of Banner activity. The SDK will notify your Listener of all possible events listed below:

banner.setBannerListener(new BannerListener() {
            @Override
            public void onBannerAdLoaded() {
                banner.setVisibility(View.VISIBLE);
            }
            @Override
            public void onBannerAdLoadFailed(IronSourceError error) {
               
            }
            @Override
            public void onBannerAdClicked() {
                
            }
            @Override
            public void onBannerAdScreenPresented() {
                
            }
            @Override
            public void onBannerAdScreenDismissed() {
                
            }
            @Override
            public void onBannerAdLeftApplication() {
                
            }
        });
Note: Do not assume the callbacks are always running on the main thread. Any UI interaction or updates resulting from ironSource callbacks need to be passed to the main thread before executing.

Step 3. Load Banner Ad Settings

  • To load a Banner ad with the default settings, call the following method:
    IronSource.loadBanner(banner);
  • We support placements, pacing and capping for Banners on the ironSource dashboard. Learn how to set up placements, capping and pacing for Banners to optimize your app’s user experience here.If you’ve set up placements for your Banner, call the following method to serve a Banner ad in a specific location:
    IronSource.loadBanner(banner, (String)placement);

 

Step 4. Destroy the Banner Ad

To destroy a banner, call the following method:

IronSource.destroyBanner(banner);

A destroyed banner can no longer be loaded. If you want to serve it again, you must initiate it again.

Step 5.  Integrate a Banner Provider

Next, integrate the ad network adapters to serve Banners through ironSource Mediation. We currently support AdmobAppLovinFacebook, Fyber and Inmobi Banners.

For better understanding of bannerSize’s behaviour per network, please follow table:

BANNER LARGE RECTANGLE SMART
AdMob Banner Large Banner IAM Medium Rectangle Banner / Leaderboard
AppLovin Banner Banner Medium Rectangle Banner / Leader
Facebook Standard Banner Large Banner Medium Rectangle Banner / Leader
Fyber Banner Banner Medium Rectangle Banner / Leader
InMobi Banner_320_50 Banner_320_50 Banner_300_250 Banner_320_50Banner_728_90

 

Done!
You are now all set up to serve Banners in your application. Verify your integration with our Integration Helper.


What’s Next? 

Follow our integration guides to integrate additional ad units:

 

Interested in integrating more mediation adapters? Check out our supported Mediation Networks.