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.
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
In your Activity’s XML layout file, add a banner view:
Code Block language xml <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 | ||
---|---|---|
| ||
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:
Code Block | ||
---|---|---|
| ||
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.
...
language | java |
---|
...
This page has moved to our new documentation:
...