Skip to main content

Banner Ad Units

Create Banner Ad Unit#

info

If you miss to Initialize the SDK, this method will fail to return a response.

To create a new banner ad, create an MesonBanner object.

val bannerAd = MesonBanner(BannerAdsActivity.this, "AD_UNIT_ID");

Set Banner Size#

Banner object takes in the width and height of the banner.

bannerAd.setBannerSize(AdSize(<width>,<height>))

Set Banner Animation#

Additional APIs to control the transition of the banner ads.

bannnerAd.setAnimationType(AnimationType animationType) {}
bannnerAd.disableHardwareAcceleration() // Heading says it is regarding banner animation but this api is not related
bannnerAd.destroy() // Heading says it is regarding banner animation but this api is not related

Register Callbacks#

Track the ad lifecycle for banner ads. All the available events for banner ads are listed below.

BannerAd.setAdListener(object:MesonBannerAdListener(){
override fun onAdImpression(bannerAd: MesonBanner, impressionData:JSONObject?) {
}
override fun onAdExpanded(bannerAd: MesonBanner) {
}
override fun onAdCollapsed(bannerAd: MesonBanner) {
}
override fun onUserLeftApplication(bannerAd: MesonBanner) {
}
override fun onAdLoadSucceeded(bannerAd: MesonBanner) {
adManager.get()?.show()
ad.mPubListener?.onAdLoadSucceeded(ad)
}
override fun onAdLoadFailed(bannerAd: MesonBanner, status: MesonAdRequestStatus) {
}
override fun onAdClicked(bannerAd: MesonBanner, params: HashMap<String, Any>) {
}
}

Load and Show#

The publisher can request for a banner ad by invoking this method. This will request an ad from all demand sources, select a winner, and once the ad is available show the ad to the user in the registered ad container.

adContainer.addView(bannerAd);
bannerAd.load();