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
- Follow the initial integration guide: https://mobilefuse.atlassian.net/wiki/pages/resumedraft.action?draftId=1347092481
- Ensure that you have a Banner Ad Placement ID to use.
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.
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
In your Activity’s XML layout file, add a banner view:
<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:
import com.mobilefuse.sdk.BannerAd; // ... BannerAd bannerAd = findViewById(R.id.bannerAd); bannerAd.loadAd();
Option 2: Create the Banner Ad programmatically
Once the MobileFuse SDK has initialized, create the
BannerAd
instance and add it to your activity’s view hierarchy:
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.
bannerAd.setListener(new BannerAdListener() { @Override public void onAdLoaded() { // Ad is loaded and can be displayed } @Override public void onAdUnavailable() { // No banner ad is available for display } @Override public void onAdComplete() { // The banner ad has completed it's display and has been closed } @Override public void onAdShowing() { // The banner ad has begun to be displayed to the user } @Override public void onAdClicked() { // The banner ad has been clicked } @Override public void onAdError(AdError error) { // An error occured - check the error argument for further details } @Override public void onAdExpanded() { // The banner ad has been interacted with, and expanded into a full-screen ad by the user } @Override public void onAdCollapsed() { // The banner ad has returned to a standard state after being expanded } });