Skip to main content
Version: 3.3.0-beta

Banner

Banner ads are classic static banners, usually located at the bottom or top of the screen. Appodeal supports traditional 320x50 banners, 728x90 tablet banners and smart banners that adjust to the size and orientation of the device.

You can use our demo banner app as a reference project.

Demo App

Fixed Positioned Banner

Display Banner At The Specific Position Of The Screen

To display banner, you need to call the following code in the activity:

Appodeal.show(this, Appodeal.BANNER) // Display banner with last position or bottom position of the screen
Appodeal.show(this, Appodeal.BANNER_BOTTOM) // Display banner at the bottom of the screen
Appodeal.show(this, Appodeal.BANNER_TOP) // Display banner at the top of the screen
Appodeal.show(this, Appodeal.BANNER_LEFT) // Display banner at the left of the screen
Appodeal.show(this, Appodeal.BANNER_RIGHT) // Display banner at the right of the screen

The method returns a boolean value indicating whether the call to the show method was passed to the appropriate SDK.

SDK can't show ads without a network connection!
BannerView should be on the top of the hierarchy and can not be overlapped by other views.

Check If Ad Is Loaded

You can check if the ad has been loaded before showing it. This method returns a boolean value indicating whether or not the banner has been loaded.

Appodeal.isLoaded(Appodeal.BANNER)

Manual Caching

By default, auto caching is enabled: Appodeal SDK starts to load Banner right after the initialization method is called.

The next banner ad starts to load after the previous one has been closed.

To disable automatic caching for banner, use the code below before SDK initialization:

Appodeal.setAutoCache(Appodeal.BANNER, false)

To cache banner use:

Appodeal.cache(this, Appodeal.BANNER)

Read more on manual caching in our FAQ.

Hide

Appodeal.hide(this, Appodeal.BANNER)

Callbacks

Appodeal.setBannerCallbacks(object : BannerCallbacks {
override fun onBannerLoaded(height: Int, isPrecache: Boolean) {
// Called when banner is loaded
}
override fun onBannerFailedToLoad() {
// Called when banner failed to load
}
override fun onBannerShown() {
// Called when banner is shown
}
override fun onBannerShowFailed() {
// Called when banner show failed
}
override fun onBannerClicked() {
// Called when banner is clicked
}
override fun onBannerExpired() {
// Called when banner is expired
}
})
info

All callbacks are called on the main thread.

Custom Positioned Banner

Display Banner In The Specified View In The Layout File

  1. Add com.appodeal.ads.BannerView to your layout file:
<com.appodeal.ads.BannerView
android:id="@+id/appodealBannerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
  1. Set view id before the SDK initialization to show banner:
Appodeal.setBannerViewId(R.id.appodealBannerView)
  1. Now you can show the banner in the view specified (Make sure that the required view is on the screen):
Appodeal.show(this, Appodeal.BANNER_VIEW)
SDK can't show ads without a network connection!
BannerView should be on the top of the hierarchy and can not be overlapped by other views.

Display Banner In Programmatically Created View

  1. Create banner view and add view to your layout:
val adView = Appodeal.getBannerView(this)
rootLayout.addView(adView)
  1. Now you can show the banner in the view specified (Make sure that the required view is on the screen):
Appodeal.show(this, Appodeal.BANNER_VIEW)
SDK can't show ads without a network connection!
BannerView should be on the top of the hierarchy and can not be overlapped by other views.

Advanced

Placements

Appodeal SDK allows you to tag each impression with different placement. To be able to use placements, you need to create them in Appodeal Dashboard. Read more about placements.

Appodeal.show(this, Appodeal.BANNER, "yourPlacementName")

If the loaded ad can't be shown in a specific placement, nothing will be shown. If auto caching is enabled, the SDK will start to cache another ad, which can affect display rate. To save the loaded ad for future use (for instance, for another placement), check if the ad can be shown before calling show method:

if (Appodeal.canShow(Appodeal.BANNER, "yourPlacementName")) {
Appodeal.show(this, Appodeal.BANNER, "yourPlacementName")
}

You can configure your impression logic for each placement.

If you have no placements or call Appodeal.show with a placement that does not exist, the impression will be tagged with default placement with corresponding settings applied.

Important!

Placement settings affect ONLY ad presentation, not loading or caching.

Check If Ad Is Initialized

To check if banner was initialized, you can use the method:

Appodeal.isInitialized(Appodeal.BANNER)

Returns true, if the banner was initialized.

Check If Autocache Is Enabled

To check if autocache is enabled for banner, you can use the method:

Appodeal.isAutoCacheEnabled(Appodeal.BANNER)

Returns true, if autocache is enabled for banner.

Get Predicted eCPM

This method returns the expected eCPM for the cached ad. The amount is calculated based on historical data for the current ad unit.

Appodeal.getPredictedEcpm(Appodeal.BANNER)
This method is reasonable to use if manual caching of ads is enabled.

Activity "Paused" State Handling

We’ll automatically handle pause and resume state for already displayed Banners on Activity on which they were displayed, however, we don’t restore displayed Banners after Activity recreation (e.g. - orientation changes) and we don’t show Banners in newly created Activities.

For display ads on newly created Activity just call Appodeal.show() method if required:

override fun onResume() {
super.onResume()
Appodeal.show(this, Appodeal.BANNER)
}

This behavior can be changed by calling Appodeal.setSharedAdsInstanceAcrossActivities(true)

(See more: Enable Shared View Ads Instance Across Activities Logic)

Destroy

If you want to hide the banner from all activities and clear the memory, call the code below:

Appodeal.destroy(Appodeal.BANNER)

Enable 728x90 Banners

To enable 728x90 banners, use the following method:

Appodeal.set728x90Banners(true)
info

The method will work if your device is larger than 7 inches

Enable Shared View Ads Instance Across Activities Logic

Appodeal SDK binds the Banner/MREC to the Activity which was passed to the Appodeal.show method.

To make it easier for you to manage View ads display logic across all Activities we added a new method in Appodeal class:

Appodeal.setSharedAdsInstanceAcrossActivities(sharedAdsInstanceAcrossActivities: Boolean)
  • When this method is used with the true parameter, the SDK will show AdView on all new activities without calling additional code from your side.
  • If you want to control the display yourself, you can call the method with the false parameter.
caution

In this case, this parameter is false, be careful with changing orientation or moving to a new activity, the Banner/MREC will not be shown automatically, since it was bound to the previous activity. If you want to hide the Banner/MREC, you need to call the Appodeal.hide() method with the parameters of the activity to which the Banner/MREC was bound.

You can also check the current state of this logic:

Appodeal.isSharedAdsInstanceAcrossActivities()
info

Shared View Ads Instance Across Activities is disabled by default

Disable Banner Refresh Animation

To disable banner refresh animation, use:

Appodeal.setBannerAnimation(false)
info

Banner animation is enabled by default.

Disable Smart Banners

Smart banners are the banner ads that automatically fit the screen size. Using them helps to deal with the increasing fragmentation of the screen sizes on different devices.

To disable them, use the following method:

Appodeal.setSmartBanners(false)
info

Smart banners is enabled by default.

Check Viewability

You can always check in logs if show was tracked and your ad is visible.

You will see the Banner [Notify Shown] log if show was tracked successfully.

Appodeal  com.example.app  D Banner [Notify Shown]