multiple ad units migration banner

This guide explains how to integrate the LevelPlay APIs using an ad unit ID as a waterfall identifier, to load and display banner ads.

Create banner ad and set size

Create the banner ad unit and set the banner size. The creation of the banner object should be done after receiving  OnInitSuccess callback

// Create the banner view and set the ad unit id
LevelPlayBannerAdView levelPlayBanner = new LevelPlayBannerAdView(context, "adUnitId");
// Create the banner view and set the ad unit id
val levelPlayBanner = LevelPlayBannerAdView(context, "adUnitId")

BANNER_SIZES_ANDROID

legacy API Ad Unit API Dimensions in dp (Width X Height)
ISBannerSize LevelPlayAdSize
ISBannerSize_BANNER bannerSize 320 x 50
ISBannerSize_LARGE largeSize 320 x 90
ISBannerSize_RECTANGLE mediumRectangleSize 300 x 250
ISBannerSize_SMART Replaced by Adaptive Ad Size (see below) Automatically renders ads to adjust size and orientation for mobile & tablets

To create the ad size follow one of these options: 

Adaptive ad size that adjusts to the screen width (recommended):
This option replaces the “SMART” integration, as it will return 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)

Adaptive ad size using fixed width ad size:
This option allows you to set a specific width. Networks that support adaptive- banner feature (Google, Yandex) will return a height based on their optimization logic based on the provided width. All other networks will return the fallback size (either BANNER or LEADERBOARD) according to the width provided.

 LevelPlayAdSize adSize = LevelPlayAdSize.createAdaptiveAdSize(context, 400);
 val adSize = createAdaptiveAdSize(context, 400)

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) 

Additional parameters

  1. Set additional parameters for the banner ad. These are optional parameters that should be defined before loading the ad. 
    1. Ad Unit Id – mandatory
    2. Placement – optional, used for reporting 
    3. AdSize – if the SDK is not initialized, the returned banner size will be nil.
    4. public void loadBanner() {
          // Create the banner view and set the ad unit id
          LevelPlayBannerAdView levelPlayBanner = new LevelPlayBannerAdView(context, "adUnitId");
          // Set the placement name
          levelPlayBanner.setPlacementName("placementName");
          // Create the adaptive ad size to support both adaptive, banner and leaderboard ) 
          LevelPlayAdSize adSize = LevelPlayAdSize.createAdaptiveAdSize(context);
       
          // required when using createAdaptive()
          if (adSize != null) {
             levelPlayBanner.setAdSize(adSize);
          }
          // Add the banner view to the container
          ViewGroup adContainer = findViewById(android.R.id.adContainer);
          adContainer.addView(levelPlayBanner);
       
          // Load the banner ad
          levelPlayBanner.loadAd();
           
          // to get actual banner layout size (either custom/standard size or adaptive)
          height = adSize.getHeight();
          width = adSize.getWidth();
      }
      
      fun loadBanner() {
       // Create the banner view and set the ad unit id
       val levelPlayBanner = LevelPlayBannerAdView(context, "adUnitId")
       // Set the placement name
       levelPlayBanner.setPlacementName("placementName")
        // Create the adaptive ad size to support both adaptive, banner and leaderboard ) 
       val adSize = createAdaptiveAdSize(context)
      // required when using createAdaptive()
       adSize?.let { levelPlayBanner.setAdSize(it) }
       // Add the banner view to the container
       val adContainer = findViewById(R.id.adContainer)
       adContainer.addView(levelPlayBanner)
       // Load the banner ad
       levelPlayBanner.loadAd()
      // get width and height for the container
      val width = adaptiveSize.getWidth()
      val height = adaptiveSize.getHeight()
      }
      

Load banner

  1. Load the banner ad
    public void loadBanner() {
        // Create the banner view and set the ad unit id
        LevelPlayBannerAdView levelPlayBanner = new LevelPlayBannerAdView(context, "adUnitId");
        // Set the placement name
        levelPlayBanner.setPlacementName("placementName");
        // Create the adaptive ad size to support both adaptive, banner and leaderboard ) 
        LevelPlayAdSize adSize = LevelPlayAdSize.createAdaptiveAdSize(context);
     
        // required when using createAdaptive()
        if (adSize != null) {
           levelPlayBanner.setAdSize(adSize);
        }
        // Add the banner view to the container
        ViewGroup adContainer = findViewById(android.R.id.adContainer);
        adContainer.addView(levelPlayBanner);
     
        // Load the banner ad
        levelPlayBanner.loadAd();
         
        // to get actual banner layout size (either custom/standard size or adaptive)
        height = adSize.getHeight();
        width = adSize.getWidth();
    }
    
    fun loadBanner() {
     // Create the banner view and set the ad unit id
     val levelPlayBanner = LevelPlayBannerAdView(context, "adUnitId")
     // Set the placement name
     levelPlayBanner.setPlacementName("placementName")
      // Create the adaptive ad size to support both adaptive, banner and leaderboard ) 
     val adSize = createAdaptiveAdSize(context)
    // required when using createAdaptive()
     adSize?.let { levelPlayBanner.setAdSize(it) }
     // Add the banner view to the container
     val adContainer = findViewById(R.id.adContainer)
     adContainer.addView(levelPlayBanner)
     // Load the banner ad
     levelPlayBanner.loadAd()
    // get width and height for the container
    val width = adaptiveSize.getWidth()
    val height = adaptiveSize.getHeight()
    }
    

Advanced banner options 

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 till 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 refresh
levelPlayBanner.pauseAutoRefresh();
// Resume refresh
levelPlayBanner.resumeAutoRefresh();
// Pause refresh
levelPlayBanner.pauseAutoRefresh()
// Resume refresh
levelPlayBanner.resumeAutoRefresh()

Destroy the Banner Ad

To destroy a banner, call the destroy method. A destroyed banner can no longer be shown  again, and to display more ads you should create a new LevelPlayBannerAdView object.

levelPlayBanner.destroy()
levelPlayBanner.destroy();

TABLE_BANNER_destroy_android

Old New
API  levelPlayBanner.destroy

TABLE_APIS_ANDROID

Old New
Banner Layout LevelPlayBannerAdView 
API InitializationListener
levelPlayBanner.loadAd
onInitializationComplete onInitSuccess
levelPlayBanner.setPlacementName
adaptiveSize.getWidth
adaptiveSize.getHeight

Set banner listeners 

Next, implement the LevelPlayBannerAdViewListener 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.

  • It is recommended to set the listener before loading the banner
  • Please note that each banner ad view should have its own listener implementation.

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 
    }
});
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 
    }
})

TABLE_BANNER_LISTENERS_ANDROID

ironSource Legacy API Ad Unit API
Listener LevelPlayBannerAdViewListener
Callbacks onAdLoaded onAdLoaded
onAdLoadFailed onAdLoadFailed
onAdClicked onAdClicked
onAdScreenPresented onAdExpanded
onAdScreenDismissed onAdCollapsed
onAdLeftApplication onAdLeftApplication
onAdDisplayed
onAdDisplayFailed

LevelPlay Ad Info

Ad Info

Learn more about LevelPlay Ad Info implementation and available fields here.