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.
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 (MREC) 300 x 250 SMART Smart Banner
(Adjusted for both mobile and tablet)If (screen width ≤ 720) 320 x 50
If (screen width > 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. */
private FrameLayout mBannerParentLayout;
private IronSourceBannerLayout mIronSourceBannerLayout;
@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() { } });
- 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.
- Please make sure to set the listeners before SDK initialization. This will ensure the SDK sends all relevant information.
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.
You can find the supported networks below, and bannerSize behaviour for each network below:
BANNER | LARGE | RECTANGLE | SMART | |
ironSource | Banner | Large Banner | Medium Rectangle | Banner / Leaderboard |
AdColony | Banner | Banner | Medium Rectangle | Banner / Leaderboard |
AdMob | Banner | Large Banner* | Medium Rectangle | Banner / Leaderboard |
AppLovin | Banner | Banner | Medium Rectangle | Banner / Leaderboard |
Chartboost | Banner | Banner | Medium Rectangle | Leaderboard |
Meta Audience Network |
Banner | Large Banner | Medium Rectangle | Banner / Leaderboard |
Fyber | Banner | Banner | Medium Rectangle | Banner / Leaderboard |
HyprMX | Banner | – | Medium Rectangle | Banner / Leaderboard |
InMobi | Banner | Banner | Medium Rectangle | Banner / Leaderboard |
Smaato | Banner | – | Medium Rectangle | Banner / – |
UnityAds | Banner | Banner | – | Banner / Leaderboard |
Vungle | Banner | Banner | Medium Rectangle | Banner / Leaderboard |
Banner Size Reference
- Banner: 320 X 50
- Large Banner: 320×90
- Medium Rectangle (MREC): 300×250
- LeaderBoard: 728X90
* AdMob define Large as 320X100
Step 6. Adaptive banners
The adaptive banner feature will allow you to receive the optimal banner size, based on an ad-width and the screen size.
While using this feature, networks that support adaptive banners (Currently AdMob and Ad Manager) will return ads with best-fit-height based on your banner size.
All other networks will continue to deliver banners according to the specified ad size.
- When you define your banner size add the “adaptive” flag
ISBannerSize.setAdaptive(true);
- Receive the ad size as part of the load-success callback onBannerAdLoaded(), both for load and refreshed banner ads, allowing you to adjust the banner view in your app.
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.