Before You Start
Before integrating ads unit in your app, you must:
- In the OpenMediation Publisher UI, create an account, create an app, and setup an ad placement using the format ‘Banner Ad’. You can follow guides here.
- Follow our steps to Android SDK Integration by integrating the OpenMediation SDK into your project.
- If you use mediation, go to Add Mediation Networks and make sure you have added the ad network SDKs and the corresponding adapters you wish to use to your app.
Banners are rectangular, system-initiated ads that served in a designated area around your live app content.
BannerAd Formats:
The OpenMediation SDK fires several events to inform you of Banner Ad activity. To display Banner Ads, one needs to create a brand new BannerAd object, setup its listeners and load the ads.
The following snippet demonstrates how to use the BannerAd class to create BannerAd objects and implement the BannerAdListener interface to receive Banner Ad events. The SDK will notify the Listener of all possible events listed below:
import com.openmediation.sdk.banner.AdSize;
import com.openmediation.sdk.banner.BannerAd;
import com.openmediation.sdk.banner.BannerAdListener;
...
BannerAd bannerAd = new BannerAd(placementId, new BannerAdListener() {
/**
* Invoked when Banner Ad are available.
*/
@Override
public void onBannerAdLoaded(String placementId, View view) {
// bannerAd is load success
}
/**
* Invoked when the end user clicked on the Banner Ad
*/
@Override
public void onBannerAdClicked(String placementId) {
// bannerAd click
}
/**
* Invoked when the call to load a Banner Ad has failed
* String error contains the reason for the failure.
*/
@Override
public void onBannerAdLoadFailed(String placementId, Error error) {
// bannerAd fail
}
});
// default size
bannerAd.setAdSize(AdSize.BANNER);
See table below for details about our supported standard banner sizes:
AdSize | Description | Dimensions in dp (WxH) |
---|---|---|
AdSize.BANNER | Standard Banner | 320 x 50 |
AdSize.MEDIUM_RECTANGLE | Medium Rectangular Banner | 300 x 250 |
AdSize.LEADERBOARD | LeaderBoard Banner | 728 x 90 |
AdSize.SMART | Smart Banner (Adjusted for both mobile and tablet) |
If (screen height ≤ 720) 320 x 50 If (screen height > 720) 728 x 90 |
Invoke loadAd method to request and cache the Banner Ad before it is available for display to users. It is strongly recommended to invoke this method a short while before the ad is to be shown.
bannerAd.loadAd()
Notes:
- The loadAd method could be called multiple times at any time, but we do not recommend continuous requests for a short period of time. Many requests in a short period of time have no added value because the opportunities of available for inventory is unlikely at this time.
- !Warning: Attempting to load a new ad from the onAdFailed() methods is strongly discouraged. If you must load an ad from onAdFailed() ensure to limit ad load retries to avoid continuous failed ad requests in situations such as limited network connectivity.
- Please do not request Banner ads regularly in the application, OpenMediation SDK will automatically refresh Banner ads regularly.
After the Banner Ad is successfully loaded by calling the loadAd in Step 2, you will be notified when the ad is ready to be shown through the onAdReady callback which will inform you the availability of ad inventory.
Once you receive the onAdReady callback, you can use code below to show and serve the Banner Ad to your users.
private RelativeLayout adParent;
...
adParent = this.findViewById(R.id.banner_ad_container);
...
@Override
public void onBannerAdLoaded(String placementId, View view) {
// bannerAd is loaded successfully
if (null != view.getParent()) {
((ViewGroup) view.getParent()).removeView(view);
}
adParent.removeAllViews();
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
adParent.addView(view, layoutParams);
}
■ R.id.banner_ad_container code as following:
<RelativeLayout
android:id="@+id/banner_ad_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
It is recommended to invoke destroy method to release BannerAd object when the Activity be destroyed.
@Override
public void onDestroy() {
if (bannerAd != null) {
bannerAd.destroy();
}
super.onDestroy();
}
You can find the supported networks below, and bannerSize behaviour for each network below:
Platforms | BANNER | MEDIUM_RECTANGLE | LEADERBOARD | SMART |
---|---|---|---|---|
AdMob | Banner | Medium Rectangle | Leaderboard | Smart |
Banner | Medium Rectangle | Leaderboard | Banner / Leaderboard | |
UnityAds | Banner | Leaderboard | Banner / Leaderboard | |
Vungle | Banner | Leaderboard | Banner / Leaderboard | |
AppLovin | Banner | Leaderboard | Banner / Leaderboard | |
IronSource | Banner | Medium Rectangle | Leaderboard | Smart |
Comments
Article is closed for comments.