Bidapp Ads
  • 🎁Ab_dout
  • Integration
    • iOS
      • Getting started
      • Additional Settings
      • App Policy Settings
      • Serverless Settings
      • Interstitial Ads
      • Rewarded Ads
      • Banner Ads
      • SKAdNetwork
      • SwiftUI
    • Android
      • Getting started
      • Additional Settings
      • App Policy Settings
      • Serverless Settings
      • Interstitial Ads
      • Rewarded Ads
      • Banner Ads
      • Jetpack Compose
  • PLUGINS
    • Kotlin Multiplatform
      • Getting started
      • Android Platform Setup
      • iOS Platfrom Setup
      • App Policy Settings
      • Interstitial Ads
      • Rewarded Ads
      • Banner Ads
    • Unreal Engine
      • Getting started
      • App Policy Settings
      • Interstitial Ads
      • Rewarded Ads
      • Banner Ads
      • MREC
    • Unity
      • Getting started
      • Android
      • iOS
      • App Policy Settings
      • Interstitial Ads
      • Rewarded Ads
      • Banner Ads
Powered by GitBook
On this page
  • Banner State
  • Stopping and Starting Auto-Refresh
  • Destroying Banners

Was this helpful?

  1. Integration
  2. Android

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 );
}
//BannerViewDelegate protocol methods 

override fun adViewDidLoadAd(adView: BannerView, adInfo: AdInfo) {
    print("Banner - adViewDidLoadAd. AdView: $adView, AdInfo: $adInfo")
}

override fun adViewDidDisplayAd(adView: BannerView, adInfo: AdInfo) {
    print("Banner - didDisplayAd. AdView: $adView, AdInfo: $adInfo")
}

override fun adViewDidFailToDisplayAd(adView: BannerView, adInfo: AdInfo, errors: Error) {
    print("Banner - didFailToDisplayAd. AdView: $adView, Error:${errors.localizedMessage}")
}

override fun adViewClicked(adView: BannerView, adInfo: AdInfo) {
    print("Banner - didClicked. AdView: $adView, AdInfo: $adInfo")
}

override fun allNetworksFailedToDisplayAd(adView: BannerView) {
    print("Banner - allNetworksFailedToDisplayAd")
}

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:

banner.isAdDisplayed()
banner.isAdDisplayed()

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).

banner.isReadyToRefresh()
banner.isReadyToRefresh()

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:

banner.stopAutorefresh()
banner.stopAutorefresh()

Start auto-refresh for a banner ad with the following code:

banner.startAutorefresh(30.0)
banner.startAutorefresh(30.0)

Manually refresh the contents with the following code. You must stop auto-refresh prior to calling refreshAd.

banner.refreshAd()
banner.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

banner.destroy()
banner.destroy()
PreviousRewarded AdsNextJetpack Compose

Last updated 11 months ago

Was this helpful?