Welcome to the Fyber Android Developer Portal

Let's get started.

Docs

Integrating Banners

Please Note!

Banners are only compatible with version 8.3.0 of the Fyber SDK and above. Please ensure you are using a recent version of the SDK with compatible ad partner bundles.

Performing the Integration

Properly integrating Banners requires updating both the developer Dashboard as well as the SDK.

Step 1: Enabling Banners

As with most of our products, you first need to configure the Fyber Dashboard before you can start coding.

  1. Go to the Dashboard and click through to your selected App.
  2. Go to Ad Formats and click on the Banner Settings Tab within your App. Make sure Status is set to On.
  3. Click Save to save your Banner configurations.

Step 2: Instantiating the Banner

First, create a BannerAdView that is used to configure the banner right away, and later used to load and attach the banner to a view in your app.

import com.fyber.ads.banners.BannerAdView;

[...]

// Before we can do anything with it, we need to instantiate the banner
BannerAdView bannerAdView = new BannerAdView(activity);

Configuring the Banner Sizes

When instantiating the banner, you may want to set the available banner sizes for each of the ad partners you have integrated. You can do so by chaining calls to withNetworkSize and passing a size from the network you wish to configure.

Please Note:

If you do not set a banner size, the default sizes will be used for each network.

Please Note:

You may call withNetworkSize multiple times and pass sizes for the same network more than once. If you do so, only the most recent size will be used. The others will be ignored.

Step 3: Loading and Attaching the Banner

Before you can show a banner on the screen, you need a view to hold the banner. You can set up this view in your xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	android:orientation="vertical">
  
  [...]

	<FrameLayout
		android:id="@+id/banner_placeholder"
		android:layout_width="match_parent"
		android:layout_height="wrap_content" />
  
  [...]

</LinearLayout>

Loading and Attaching the Banner

Once you have a view in which to place the banner, you must load the banner. This will trigger a request for a banner. Once you have a banner loaded, you can attach it to the view in your app.

import android.widget.FrameLayout;

[...]

// Loading the banner will cause a request which will provide the fill into the banner view
bannerAdView.load();

[...]

// The banner view can be gathered from the layout and then the banner attached to it
FrameLayout bannerPlaceholder = (FrameLayout) findViewById(R.id.banner_placeholder);
bannerPlaceholder.addView(bannerAdView);

The request for banners is only triggered when calling load. If you would prefer to make the banner load automatically when attached to a view, use loadOnAttach.

import android.widget.FrameLayout;

[...]

// Loading the banner when it is attached to a view will cause a request every time the banner is attached to the view
bannerAdView.loadOnAttach();

[...]

// The banner view can be gathered from the layout and then the banner attached to it
FrameLayout bannerPlaceholder = (FrameLayout) findViewById(R.id.banner_placeholder);
bannerPlaceholder.addView(bannerAdView);

Step 4: Handling User Interactions

The BannerAdListener provides callbacks that can notify you of user interaction with the banner. You receive these notifications by chaining a call to withListener when creating your BannerAdView and passing it an instance of BannerAdListener.

import com.fyber.ads.banners.BannerAd;
import com.fyber.ads.banners.BannerAdView;
import com.fyber.ads.banners.BannerAdListener;

[...]

BannerAdView bannerAdView = new BannerAdView(activity)
  .withListener(new BannerAdListener() {
		@Override
		public void onAdError(BannerAd ad, String error) {
			// Called when the banner triggered an error
      Log.d(TAG, "Something went wrong with the request: " + error);
		}

		@Override
		public void onAdLoaded(BannerAd ad) {
			// Called when the banner has been successfully loaded
      Log.d(TAG, "Banner successfully loaded");
		}

		@Override
		public void onAdClicked(BannerAd ad) {
			// Called when the banner was clicked
      Log.d(TAG, "User clicked on banner");
		}

		@Override
		public void onAdLeftApplication(BannerAd ad) {
			// Called when the banner interaction causes an external application to be open
      Log.d(TAG, "User directed out of app by banner");
		}
	});

You've set up Banners!

Next Steps

Want to get the most out of your Rewarded Videos with mediation?

Looking to dive into some advanced options?

Ready to set up another Fyber product?

Integrating Banners


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.