Banner Ads
To load a banner, create a BannerView and add it as a subview of your view hierarchy.
You can create banners of either 320x50 or 300x250 size:
//add banners to view
public void addBanner_320x50_to_view(View view, BannerViewDelegate delegate) {
BannerView banner = new BannerView(Activity activity).banner(AdFormat.banner_320x50);
banner.setBannerViewDelegate(bannerShowDelegate)
view.addView(banner);
}
public void addBanner_300x250_to_view(View view, BannerViewDelegate delegate) {
BannerView banner = new BannerView(Activity activity).banner(AdFormat.banner_300x250);
banner.setBannerViewDelegate(bannerShowDelegate)
view.addView(banner);
}//add banners to view
fun addBanner_320x50_to_view(view:View) {
val banner = BannerView(activity:Activity).banner(AdFormat.banner_320x50)
banner.setBannerViewDelegate(bannerShowDelegate)
view.addView(banner)
}
fun addBanner_300x250_to_view(view:View) {
val banner = BannerView(activity:Activity).banner(AdFormat.banner_300x250)
banner.setBannerViewDelegate(bannerShowDelegate)
view.addView(banner)
}Implement BannerViewDelegate so that you are notified of when your ad is ready and of other ad-related events.
//BannerViewDelegate protocol methods
@Override
public void adViewDidLoadAd(BannerView adView, @NonNull AdInfo adInfo) {
System.out.println("Banner - adViewDidLoadAd. AdView: " + adView + ", AdInfo: " + adInfo);
}
@Override
public void adViewDidDisplayAd(@NonNull BannerView adView, @NonNull AdInfo adInfo) {
System.out.println("Banner - didDisplayAd. AdView: " + adView + ", AdInfo: " + adInfo);
}
@Override
public void adViewDidFailToDisplayAd(@NonNull BannerView adView, @NonNull AdInfo adInfo, Error errors) {
System.out.println("Banner - didFailToDisplayAd. AdView: " + adView + ", Error: " + errors.getLocalizedMessage());
}
@Override
public void adViewClicked(@NonNull BannerView adView, @NonNull AdInfo adInfo) {
System.out.println("Banner - didClicked. AdView: " + adView + ", AdInfo: " + adInfo);
}
@Override
public void allNetworksFailedToDisplayAd(@NonNull BannerView adView) {
System.out.println("Banner - allNetworksFailedToDisplayAd. AdView: " + adView );
}Banner State
To determine whether an advertisement banner is currently being displayed or not you can use function, that returns a boolean value, specifically true if an ad is present and visible on the screen, and false otherwise:
To check whether the SDK is initialized and if the banner is ready for display or not you can use function, that returns a boolean value (true if the conditions are met and false otherwise).
Stopping and Starting Auto-Refresh
There may be cases when you would like to stop auto-refresh, for instance, when you hide a banner ad or want to manually refresh.
Stop auto-refresh for a banner ad with the following code:
Start auto-refresh for a banner ad with the following code:
Manually refresh the contents with the following code. You must stop auto-refresh prior to calling refreshAd.
Destroying Banners
Once you're finished with a banner ad, it's essential to clean up its resources by invoking the destroy() method. Neglecting this step could lead to a deterioration in your app's performance
Last updated
Was this helpful?