Banner Integration for Xamarin 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 you have correctly integrated the ironSource Xamarin Plugin in 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 If (screen height ≤ 720) 320 x 50
    If (screen height > 720) 728 x 90

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. To receive these events, we suggest the following:

  1. Create a class which inherits from LevelPlayBannerDelegate. We recommend to create a separate class for each delegate

    public class LevelPlayBannerListener : Activity, ILevelPlayBannerListener
            {
                private Activity activity;
                public LevelPlayBannerListener(Activity activity)
                {
                    this.activity = activity;
                }
                // Called after a banner has been clicked.
                public void OnAdClicked(AdInfo adinfo)
                {
                }
                // Called when a user would be taken out of the application context.
                public void OnAdLeftApplication(AdInfo adInfo)
                {
                }
                // Called after a banner ad has been successfully loaded
                public void OnAdLoaded(AdInfo adInfo)
                {
                }
                // Called after a banner has attempted to load an ad but failed.
                public void OnAdLoadFailed(IronSourceError ironSourceError)
                {
                }
                // Called after a full screen content has been dismissed
                public void OnAdScreenDismissed(AdInfo adInfo)
                {
                }
                // Called when a banner is about to present a full screen content.            
                public void OnAdScreenPresented(AdInfo adInfo)
                {
                }
            }
        }

  2. Create and instantiate a LevelPlayBannerListener, FrameLayout and IronSourceBannerLayout objects. Set the delegate using the new object and start listening to ILevelPlayBannerListener.
    Important In this implementation bannerContainer is created in activity_main.xml
    LevelPlayBannerListener mLevelPlayBannerListener;
    IronSourceBannerLayout mBanner;
    FrameLayout bannerContainer
    // Define the listener 
    mLevelPlayBannerListener = new LevelPlayBannerListener(this);
    bannerContainer = FindViewById<FrameLayout>(Resource.Id.bannerContainer);
    mBanner = IronSource.CreateBanner(this, ISBannerSize.Banner);
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.WrapContent);
    bannerContainer.AddView(mBanner, 0, layoutParams);
    // Set the delegate 
    mBanner.LevelPlayBannerListener = mLevelPlayBannerListener;
    //After initialization load banner
    IronSource.loadBanner(banner);
    


    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(mBanner);

Note:  SDK will not show more than one banner at a time.

Step 4. Destroy the Banner Ad

To destroy a banner, call the following method:

IronSource.DestroyBanner(mBanner);

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 Unity LevelPlay. We currently support ironSource, AdmobAppLovin and Meta Audience Network Banners.

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

BANNER LARGE RECTANGLE SMART
ironSource Banner Large Banner / Leaderboard
AdMob Banner Large Banner IAM Medium Rectangle Banner / Leaderboard
AppLovin Banner Banner Medium Rectangle Banner / Leader
Meta Audience
Network
Standard Banner Large Banner Medium Rectangle Banner / Leader
UnityAds Banner Banner Banner / Leaderboard
Vungle Banner Banner Medium Rectangle Banner / Leaderboard

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