Documentation

​
​

Development

User Acquisition

Monetization

Industry

LevelPlay SDK - Android

Unity SDK

Android SDK

iOS SDK

Adobe AIR SDK

Flutter SDK

React Native SDK

LevelPlay SDK - Android

Unity LevelPlay
​
​
Android SDK
  • Get started
  • Regulations and settings
  • Ad formats
    • Rewarded ads
    • Interstitial
    • Banner and MREC
      • Migrate to banner ad unit API
    • Native ads
  • Mediated networks
  • Test your integration
  1. Grow your game
  2. Unity LevelPlay
  3. LevelPlay SDK
  4. LevelPlay SDK for Android developers

Banner integration for Android

Integrate banner ads by initializing the SDK, creating banner ad objects post-initialization, and setting appropriate ad sizes and positions.
Read time 6 minutes
Last updated 7 months ago

Banners are a rectangular, system-initiated ads that can be either static or animated, and are served in a designated area around your live app content.
Note
This documentation is relevant for SDK 8.9.0+.

Prerequisites

  • Make sure that you have correctly integrated the LevelPlay SDK into your application. Integration is outlined here.
  • Make sure to initialize the SDK using LevelPlay Initialization API.
  • Find the AdUnitID in LevelPlay dashboard.

Create Banner Ad Object and Set Size

The creation of the banner ad object should be done after receiving onInitSuccess callback.
// Create ad configuration - optionalLevelPlayAdSize adSize = LevelPlayAdSize.BANNER;LevelPlayBannerAdView.Config adConfig = new LevelPlayBannerAdView.Config.Builder() .setAdSize(adSize) .setPlacementName("placementName") .build();// Create the banner view and set the ad unit idLevelPlayBannerAdView levelPlayBanner = new LevelPlayBannerAdView(context, "adUnitId", adConfig);
// Create ad configuration - optionalval adSize = LevelPlayAdSize.BANNERval adConfig = LevelPlayBannerAdView.Config.Builder().setAdSize(adSize).setPlacementName("placementName").build()// Create the banner view and set the ad unit idval levelPlayBanner = LevelPlayBannerAdView(context, "adUnitId", adConfig)

Banner Sizes

LevelPlayAdSize

Description

Dimensions in dp (Width X Height)

BANNERStandard banner320 x 50
LARGELarge banner728 x 90
MEDIUM_RECTANGLEMedium Rectangular (MREC)300 x 250
AdaptiveAutomatically renders ads to adjust size and orientation for mobile & tabletsDevice width X recommended height
To create the ad size follow one of these options:

Adaptive ad size that adjusts to the screen width (recommended)

This option returns BANNER or LEADERBOARD according to the device type. Networks that supports adaptive feature (Google, Yandex) will return the a height based on their optimization logic.
LevelPlayAdSize adSize = LevelPlayAdSize.createAdaptiveAdSize(context);
val adSize = createAdaptiveAdSize(context)
Specific banner size: This option allows you to set specifically a banner size: BANNER, LARGE, MEDIUM_RECTANGLE.
levelPlayBanner.setAdSize(LevelPlayAdSize.MEDIUM_RECTANGLE);
levelPlayBanner.setAdSize(LevelPlayAdSize.MEDIUM_RECTANGLE)

Placements

We support placements in banners for reporting only. Placements should be set before the loadAd, to affect all reloaded ads.
// Set the placement namelevelPlayBanner.setPlacementName("placementName");
// Set the placement namelevelPlayBanner.setPlacementName("placementName")

Set Banner Listener

Implement the LevelPlayBannerAdViewListener in your code to get informed of ad delivery.
  • It is recommended to set the listener before loading the banner ad.
  • Each banner ad should have its own listener implementation.
  • Callbacks run on the main thread.
  • When callbacks are not supported by all networks, they are marked as optional.
levelPlayBanner.setBannerListener(new LevelPlayBannerAdViewListener() {@Overridepublic void onAdLoaded(@NonNull LevelPlayAdInfo adInfo) {// Ad was loaded successfully }@Overridepublic void onAdLoadFailed(@NonNull LevelPlayAdError error) {// Ad load failed}@Overridepublic void onAdDisplayed(@NonNull LevelPlayAdInfo adInfo) {// Ad was displayed and visible on screen}@Overridepublic void onAdDisplayFailed(@NonNull LevelPlayAdInfo adInfo, @NonNull LevelPlayAdError error) {// Optional. Ad failed to be displayed on screen }@Overridepublic void onAdClicked(@NonNull LevelPlayAdInfo adInfo) {// Ad was clicked}@Overridepublic void onAdExpanded(@NonNull LevelPlayAdInfo adInfo) {// Optional. Ad is opened on full screen }@Overridepublic void onAdCollapsed(@NonNull LevelPlayAdInfo adInfo) {// Optional. Ad is restored to its original size }@Overridepublic void onAdLeftApplication(@NonNull LevelPlayAdInfo adInfo) // Optional. User pressed on the ad and was navigated out of the app });
levelPlayBanner.setBannerListener(object: LevelPlayBannerAdViewListener {override fun onAdLoaded(adInfo: LevelPlayAdInfo) {// Ad was loaded successfully }override fun onAdLoadFailed(error: LevelPlayAdError) {// Ad load failed}override fun onAdDisplayed(adInfo: LevelPlayAdInfo) {// Ad was displayed and visible on screen}override fun onAdDisplayFailed(adInfo: LevelPlayAdInfo, error: LevelPlayAdError) {// Optional. Ad failed to be displayed on screen }override fun onAdClicked(adInfo: LevelPlayAdInfo) {// Ad was clicked}override fun onAdExpanded(adInfo: LevelPlayAdInfo) {// Optional. Ad is opened on full screen}override fun onAdCollapsed(adInfo: LevelPlayAdInfo) {// Optional. Ad is restored to its original size }override fun onAdLeftApplication(adInfo: LevelPlayAdInfo) {// Optional. User pressed on the ad and was navigated out of the app }})

LevelPlay Ad Info

The LevelPlayAdInfo parameter includes information about the loaded ad.

Load Banner Ad

To load a banner ad use loadAd.
// Load the banner adlevelPlayBanner.loadAd();
// Load the banner adlevelPlayBanner.loadAd()

Pause and Resume Banner Refresh

You can pause banner refresh in your code if the refresh value was defined in the platform. Use the following methods to stop the automatic refresh of the banner ad, or re-enable it after pausing.
Note
When the banner is displayed again, it will complete the time until refresh from the time it was paused.
  • pauseAutoRefresh - pauses auto-refresh of the banner ad.
  • resumeAutoRefresh - resumes auto-refresh of the banner ad after it has been paused.
// Pause refreshlevelPlayBanner.pauseAutoRefresh();// Resume refreshlevelPlayBanner.resumeAutoRefresh();
// Pause refreshlevelPlayBanner.pauseAutoRefresh()// Resume refreshlevelPlayBanner.resumeAutoRefresh()

Destroy Banner Ad

To destroy a banner, call the destroy method.
A destroyed banner can no longer be shown again. To display more ads, create a new LevelPlayBannerAdView object.
levelPlayBanner.destroy()
levelPlayBanner.destroy();

Full Implementation Example of Banner Ads

Here is an example for creating and loading a banner ad using adaptive banner size.
public void createAndLoadBanner() {// Create ad configuration - optionalLevelPlayAdSize adSize = LevelPlayAdSize.BANNER;LevelPlayBannerAdView.Config adConfig = new LevelPlayBannerAdView.Config.Builder() .setAdSize(adSize) .setPlacementName("placementName") .build();// Create the banner view and set the ad unit idLevelPlayBannerAdView levelPlayBanner = new LevelPlayBannerAdView(context, "adUnitId", adConfig);// Add the banner view to the containerViewGroup adContainer = findViewById(android.R.id.adContainer);adContainer.addView(levelPlayBanner);levelPlayBanner.setBannerListener(new LevelPlayBannerAdViewListener() { @Override public void onAdLoaded(@NonNull LevelPlayAdInfo adInfo) { // Ad was loaded successfully } @Override public void onAdLoadFailed(@NonNull LevelPlayAdError error) { // Ad load failed } @Override public void onAdDisplayed(@NonNull LevelPlayAdInfo adInfo) { // Ad was displayed and visible on screen } @Override public void onAdDisplayFailed(@NonNull LevelPlayAdInfo adInfo, @NonNull LevelPlayAdError error) { // Ad failed to be displayed on screen } @Override public void onAdClicked(@NonNull LevelPlayAdInfo adInfo) { // Ad was clicked } @Override public void onAdExpanded(@NonNull LevelPlayAdInfo adInfo) { // Ad is opened on full screen } @Override public void onAdCollapsed(@NonNull LevelPlayAdInfo adInfo) { // Ad is restored to its original size } @Override public void onAdLeftApplication(@NonNull LevelPlayAdInfo adInfo) { // User pressed on the ad and was navigated out of the app }});// Load the banner adlevelPlayBanner.loadAd();// To get actual banner layout size (either custom/standard size or adaptive)int height = adSize.getHeight();int width = adSize.getWidth();}
public fun createAndLoadBanner() {// Create ad configuration - optionalval adSize = LevelPlayAdSize.BANNERval adConfig = LevelPlayBannerAdView.Config.Builder().setAdSize(adSize).setPlacementName("placementName").build()// Create the banner view and set the ad unit idval levelPlayBanner = LevelPlayBannerAdView(context, "adUnitId", adConfig)// Add the banner view to the containerval adContainer = findViewById<ViewGroup>(R.id.adContainer)adContainer.addView(levelPlayBanner)levelPlayBanner.setBannerListener(object: LevelPlayBannerAdViewListener {override fun onAdLoaded(adInfo: LevelPlayAdInfo) { // Ad was loaded successfully }override fun onAdLoadFailed(error: LevelPlayAdError) { // Ad load failed}override fun onAdDisplayed(adInfo: LevelPlayAdInfo) { // Ad was displayed and visible on screen}override fun onAdDisplayFailed(adInfo: LevelPlayAdInfo, error: LevelPlayAdError) { // Ad failed to be displayed on screen}override fun onAdClicked(adInfo: LevelPlayAdInfo) { // Ad was clicked}override fun onAdExpanded(adInfo: LevelPlayAdInfo) { // Ad is opened on full screen}override fun onAdCollapsed(adInfo: LevelPlayAdInfo) { // Ad is restored to its original size}override fun onAdLeftApplication(adInfo: LevelPlayAdInfo) { // User pressed on the ad and was navigated out of the app }})// Load the banner adlevelPlayBanner.loadAd()// Get width and height for the containerval width = adSize.getWidth()val height = adSize.getHeight()}

LevelPlay Mediation Demo App

The Integration Demo application demonstrates how to integrate banner Ad Unit APIs in your app.
Download Android Demo Application
Verify your integration with our Integration Test Suite.

Next steps

Follow our integration guides to integrate additional Banner Ad networks or configure additional ad formats:
  • Add Mediation Networks
  • Rewarded Ads
  • Interstitial Ads
  • Native Ads

Copyright © 2026 Unity Technologies
LegalPrivacy PolicyCookiesDocumentation Terms of UseDo Not Sell or Share My Personal InformationYour Privacy Choices (Cookie Settings)

"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S and elsewhere (more info here). Other names or brands are trademarks of their respective owners.

Some pages are machine-translated for convenience, and may contain inaccuracies. In the event of conflicting information, the English version is authoritative.

  • On this page
    • Prerequisites

    • Create Banner Ad Object and Set Size

      • Banner Sizes

      • Adaptive ad size that adjusts to the screen width (recommended)

      • Placements

    • Set Banner Listener

      • LevelPlay Ad Info

    • Load Banner Ad

    • Pause and Resume Banner Refresh

    • Destroy Banner Ad

    • Full Implementation Example of Banner Ads

    • LevelPlay Mediation Demo App

    • Next steps


Report a problem with this page