Follow the instructions below to create a Banner ad:
After your adunitId
is generated, you can find it on the Meson UI. Add adunitId
into the MesonBanner
object and pass the ActivityContext
.
val bannerAd = MesonBanner(this, "AD_UNIT_ID")
MesonBanner bannerAd = new MesonBanner(this, "AD_UNIT_ID");
The banner object takes in the width and height of the banner.
bannerAd.setBannerSize(AdSize(<width>,<height>))
bannerAd.setBannerSize(new AdSize(<width>,<height>));
Additional APIs to provide more control over the banner ads.
bannerAd.disableHardwareAcceleration() // Use this for android devices with RAM less than 1GB to reduce hardware resource usage
bannerAd.disableHardwareAcceleration(); // Use this for android devices with RAM less than 1GB to reduce hardware resource usage
Track the ad lifecycle for banner ads. All the available events for banner ads are listed below.
bannerAd.setAdListener(object: MesonBannerAdListener() {
override fun onAdImpression(ad: MesonBanner, mesonAdData: MesonAdData?) {
}
override fun onAdExpanded(ad: MesonBanner) {
}
override fun onAdCollapsed(ad: MesonBanner) {
}
override fun onUserLeftApplication(ad: MesonBanner) {
}
override fun onAdLoadSucceeded(ad: MesonBanner) {
}
override fun onAdLoadFailed(ad: MesonBanner, status: MesonAdRequestStatus) {
}
override fun onAdClicked(ad: MesonBanner, params: HashMap<String, Any>) {
}
})
bannerAd.setAdListener(new MesonBannerAdListener() {
@Override
public void onUserLeftApplication(MesonBanner mesonBanner) {
super.onUserLeftApplication(mesonBanner);
}
@Override
public void onAdImpression(MesonBanner mesonBanner, @Nullable MesonAdData mesonAdData) {
super.onAdImpression(mesonBanner, mesonAdData);
}
@Override
public void onAdClicked(MesonBanner mesonBanner, @NonNull HashMap<String, Object> hashMap) {
super.onAdClicked(mesonBanner, hashMap);
}
@Override
public void onAdLoadFailed(MesonBanner mesonBanner, @NonNull MesonAdRequestStatus mesonAdRequestStatus) {
super.onAdLoadFailed(mesonBanner, mesonAdRequestStatus);
}
@Override
public void onAdLoadSucceeded(MesonBanner mesonBanner) {
super.onAdLoadSucceeded(mesonBanner);
}
@Override
public void onAdCollapsed(@NonNull MesonBanner mesonBanner) {
super.onAdCollapsed(mesonBanner);
}
@Override
public void onAdExpanded(@NonNull MesonBanner mesonBanner) {
super.onAdExpanded(mesonBanner);
}
});
You can request a banner ad by invoking this method from demand sources and selecting a winner. When the ad is available, it is shown to the user in the registered ad container.
adContainer.addView(bannerAd)
bannerAd.load()
adContainer.addView(bannerAd);
bannerAd.load();
Use this method when the banner is no longer needed. We recommend using this onDestroy of the Activity.
bannerAd.destroy()
bannerAd.destroy();