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
    (Adjusted for both mobile and tablet)
    If (screen height ≤ 720) 320 x 50
    If (screen height > 720) 728 x 90

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. */
	
    protected void onCreate(Bundle savedInstanceState) {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.Main);
 
        // YOUR OTHER CODE //
        // YOUR OTHER CODE //
        // YOUR OTHER CODE //
        IronSource.Init(this, "YOUR_APP_KEY", IronSource.AD_UNIT.Banner);
 
        FrameLayout bannerContainer = FindViewById<FrameLayout>(Resource.Id.bannerContainer);
        IronSourceBannerLayout mBanner = IronSource.CreateBanner(this, ISBannerSize.Banner);
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MatchParent,FrameLayout.LayoutParams.WrapContent);
        bannerContainer.addView(mBanner, 0, layoutParams);
 
        mBanner.BannerListener = new BannerListener() {
                public void OnBannerAdLoaded() {
                // Called after a banner ad has been successfully loaded
                }
 
                public void OnBannerAdLoadFailed(IronSourceError error) {
                // <span>Called after a banner has attempted to load an ad but failed.</span>
                    RunOnUiThread(() => {
                          bannerContainer.RemoveAllViews();
                       });
                }
 
                public void OnBannerAdClicked() {
                // Called after a banner has been clicked.
                }
 
                public void OnBannerAdScreenPresented() {
                // Called when a banner is about to present a full screen content.
                }
 
                public void OnBannerAdScreenDismissed() {
                // Called after a full screen content has been dismissed
                }
 
                public void OnBannerAdLeftApplication() {
                // Called when a user would be taken out of the application context.
                }
            };
 
        IronSource.LoadBanner(mBanner);
        // 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:

mBanner.BannerListener = new BannerListener() {
           // Called after a banner ad has been successfully loaded
            public void OnBannerAdLoaded() {
                
            }
            // Called after a banner has attempted to load an ad but failed.
            public void OnBannerAdLoadFailed(IronSourceError error) {
               RunOnUiThread(() => {
                    bannerContainer.RemoveAllViews();
               });
            }
            // Called after a banner has been clicked.
            public void OnBannerAdClicked() {
                
            }
            // Called when a banner is about to present a full screen content.
            public void OnBannerAdScreenPresented() {
                
            }
            // Called after a full screen content has been dismissed
            public void OnBannerAdScreenDismissed() {
                
            }
            // Called when a user would be taken out of the application context.
            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(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 ironSource Mediation. We currently support ironSource, AdmobAppLovin and Facebook 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
Facebook Standard Banner Large Banner Medium Rectangle Banner / Leader

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