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.
Display Banner At The Specific Position Of The Screen
To display banner, you need to call the following code in the activity:
- Kotlin
- Java
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
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.
BannerView
should be on the top of the hierarchy and can not be overlapped by other views.Display Banner In The Specified View In The Layout File
- 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" />
- Set view id before the SDK initialization to show banner:
- Kotlin
- Java
Appodeal.setBannerViewId(R.id.appodealBannerView)
Appodeal.setBannerViewId(R.id.appodealBannerView);
- Now you can show the banner in the view specified (Make sure that the required view is on the screen):
- Kotlin
- Java
Appodeal.show(this, Appodeal.BANNER_VIEW)
Appodeal.show(this, Appodeal.BANNER_VIEW);
BannerView
should be on the top of the hierarchy and can not be overlapped by other views.Display Banner In Programmatically Created View
- Create banner view and add view to your layout:
- Kotlin
- Java
val adView = Appodeal.getBannerView(this)
rootLayout.addView(adView)
BannerView adView = Appodeal.getBannerView(this);
rootLayout.addView(adView);
- Now you can show the banner in the view specified (Make sure that the required view is on the screen):
- Kotlin
- Java
Appodeal.show(this, Appodeal.BANNER_VIEW)
Appodeal.show(this, Appodeal.BANNER_VIEW);
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.
- Kotlin
- Java
Appodeal.isLoaded(Appodeal.BANNER)
Appodeal.isLoaded(Appodeal.BANNER);
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.
- Kotlin
- Java
Appodeal.show(this, Appodeal.BANNER, "yourPlacementName")
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:
- Kotlin
- Java
if (Appodeal.canShow(Appodeal.BANNER, "yourPlacementName")) {
Appodeal.show(this, Appodeal.BANNER, "yourPlacementName")
}
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.
Placement settings affect ONLY ad presentation, not loading or caching.
Callbacks
- Kotlin
- Java
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
}
})
Appodeal.setBannerCallbacks(new BannerCallbacks() {
@Override
public void onBannerLoaded(int height, boolean isPrecache) {
// Called when banner is loaded
}
@Override
public void onBannerFailedToLoad() {
// Called when banner failed to load
}
@Override
public void onBannerShown() {
// Called when banner is shown
}
@Override
public void onBannerShowFailed() {
// Called when banner show failed
}
@Override
public void onBannerClicked() {
// Called when banner is clicked
}
@Override
public void onBannerExpired() {
// Called when banner is expired
}
});
All callbacks are called on the main thread.
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:
- Kotlin
- Java
Appodeal.setAutoCache(Appodeal.BANNER, false)
Appodeal.setAutoCache(Appodeal.BANNER, false);
To cache banner use:
- Kotlin
- Java
Appodeal.cache(this, Appodeal.BANNER)
Appodeal.cache(this, Appodeal.BANNER);
Read more on manual caching in our FAQ.
Check If Ad Is Initialized
To check if banner was initialized, you can use the method:
- Kotlin
- Java
Appodeal.isInitialized(Appodeal.BANNER)
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:
- Kotlin
- Java
Appodeal.isAutoCacheEnabled(Appodeal.BANNER)
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.
- Kotlin
- Java
Appodeal.getPredictedEcpm(Appodeal.BANNER)
Appodeal.getPredictedEcpm(Appodeal.BANNER);
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:
- Kotlin
- Java
override fun onResume() {
super.onResume()
Appodeal.show(this, Appodeal.BANNER)
}
@Override
public void 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)
Hide
- Kotlin
- Java
Appodeal.hide(this, Appodeal.BANNER)
Appodeal.hide(this, Appodeal.BANNER);
Destroy
If you want to hide the banner from all activities and clear the memory, call the code below:
- Kotlin
- Java
Appodeal.destroy(Appodeal.BANNER)
Appodeal.destroy(Appodeal.BANNER);
Enable 728x90 Banners
To enable 728x90 banners, use the following method:
- Kotlin
- Java
Appodeal.set728x90Banners(true)
Appodeal.set728x90Banners(true);
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:
- Kotlin
- Java
Appodeal.setSharedAdsInstanceAcrossActivities(sharedAdsInstanceAcrossActivities: Boolean)
Appodeal.setSharedAdsInstanceAcrossActivities(boolean sharedAdsInstanceAcrossActivities);
- 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 theBanner/MREC
, you need to call theAppodeal.hide()
method with the parameters of the activity to which theBanner/MREC
was bound.
You can also check the current state of this logic:
- Kotlin
- Java
Appodeal.isSharedAdsInstanceAcrossActivities()
Appodeal.isSharedAdsInstanceAcrossActivities();
Shared View Ads Instance Across Activities is disabled by default
Disable Banner Refresh Animation
To disable banner refresh animation, use:
- Kotlin
- Java
Appodeal.setBannerAnimation(false)
Appodeal.setBannerAnimation(false);
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:
- Kotlin
- Java
Appodeal.setSmartBanners(false)
Appodeal.setSmartBanners(false);
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.
- Log
Appodeal com.example.app D Banner [Notify Shown]