Banner
Banner ads are classic static banners, which are usually located at the bottom or top of the advertisement.
Appodeal supports traditional 320x50 banners, tablet banners 728x90 and smart banners that adjust to the size and orientation of the device.
You can display only one view for banner on the screen.
You can use our demo app as a reference project.
Display Banner At The Specific 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
SDK can't show ads without a network connection!
Appodeal.show()
returns a boolean value indicating whether the show method call was passed to the appropriate SDK.
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" android:visibility="gone" />
Appodeal.setBannerViewId(R.id.appodealBannerView);
Appodeal.show(this, Appodeal.BANNER_VIEW);
Important!
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:
BannerView adView = Appodeal.getBannerView(this); frameLayout.addView(adView);
Appodeal.show(this, Appodeal.BANNER_VIEW);
Check If Ad Is Loaded
Appodeal.isLoaded(Appodeal.BANNER);
Placements
Appodeal SDK allows you to tag each impression with different placement. To use placements, you need to create placements in Appodeal Dashboard. Read more about placements.
To show an ad with placement, you have to call show method like this in your activity:
Appodeal.show(this, Appodeal.BANNER, "yourPlacementName");
If the loaded ad can’t be shown for a specific placement, nothing will be shown.
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 and its settings will be applied.
Important!
Placement settings affect ONLY ad presentation, not loading or caching.
Callbacks
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 } });
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 Appodea.show()
method if required.
@Override public void onResume() { super.onResume(); Appodeal.show(this, Appodeal.BANNER_TOP); }
This behavior can be changed by calling Appodeal.setSharedAdsInstanceAcrossActivities(true)
(See more: Enable Shared View Ads Instance Across Activities Logic)
Hide
Appodeal.hide(this, Appodeal.BANNER);
Destroy
If you want to hide the banner from all activities and clear the memory, call the code below:
Appodeal.destroy(Appodeal.BANNER);
Configuration
Enable 728*90 Banners
To enable 728*90 banners, use the following method:
Appodeal.set728x90Banners(true);
Disable Banner Refresh Animation
To disable banner refresh animation, use:
Appodeal.setBannerAnimation(false);
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. In the Appodeal SDK, the smart banners are enabled by default. To disable them, use the following method:
Appodeal.setSmartBanners(false);
Check If Ad Is Initialized
To check if banner was initialized, you can use the method:
Appodeal.isInitialized(Appodeal.BANNER);
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);
true
, if autocache is enabled for banner.Get Predicted eCPM
To get the predicted eCPM from the next block in the caching queue, use the method:
Appodeal.getPredictedEcpm(Appodeal.BANNER);
This method is reasonable to use if manual caching of ads is enabled.
Enable Shared View Ads Instance Across Activities Logic
Starting from SDK 2.8.1 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(boolean sharedAdsInstanceAcrossActivities); // Default - false
- 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.
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. By default value is false
:
Appodeal.isSharedAdsInstanceAcrossActivities();