Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Banner ads are typically shown in a fixed position at the top or bottom of your app. They provide a great way to add an additional revenue stream with minimal impact to the flow and usage of your app.

The Mo/bileFuse SDK also supports delivery of expandable rich-media banner ads by default, which are more interactive and engaging than standard banner placements.

Prerequisites

Display a banner ad in your app

A banner ad is implemented into your app as a UI View - you therefore have two options for implementation - either you can adjust your applications layout XML to include a position for your banner ad, or you can programmatically create, add, and remove the banner ad view as needed.

Info

Note: Ensure that you adjust the user interface of your app to account for the positioning of the banner. You should leave a margin between the displayed banner ad and your app UI to avoid potential mis-clicks on the ad creative.

Option 1. Create the banner ad in your layout XML

Option 2. Create the banner ad programatically

Option 1: Create a banner ad in your layout XML

  1. In your Activity’s XML layout file, add a banner view:

    Code Block
    languagexml
    <com.mobilefuse.sdk.BannerAd
                android:id="@+id/bannerAd"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:mobilefuseAdSize="BANNER"
                app:mobilefusePlacementId="<YOUR BANNER PLACEMENT ID>"
                />

Note that the <YOUR BANNER PLACEMENT ID> should be replaced with a valid banner placement ID.

2. Once you have initialized the MobileFuse SDK, request that the banner ad is loaded into the view:

Code Block
languagejava
import com.mobilefuse.sdk.BannerAd;
// ...
BannerAd bannerAd = findViewById(R.id.bannerAd);
bannerAd.loadAd();

Option 2: Create the Banner Ad programmatically

  1. Once the MobileFuse SDK has initialized, create the BannerAd instance and add it to your activity’s view hierarchy:

Code Block
languagejava
import com.mobilefuse.sdk.BannerAd;
// ...
String bannerPlacementId = "000000";
BannerAd bannerAd = new BannerAd(this, bannerPlacementId, BannerAd.AdSize.BANNER);

ViewGroup bannerContainer = findViewById(R.id.adContainer);
bannerContainer.addView(bannerAd);

bannerAd.loadAd();

Listening for event callbacks

Optionally, you can create a BannerAdListener to receive events during the banner ad’s lifecycle.

...

languagejava

...

This page has moved to our new documentation:

...