The second way to display banner ad is to add its view to your view hierarchy. To do this just add MpsBannerAdView to your xml layout file in a way like this:
<com.nbcuni.mps.widget.MpsBannerAdView
android:id="@+id/mps_ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Instantiate an object of this view in a way of your app using standard findViewById, butterknife, databinding or anything else. For example:
MpsBannerAdView mpsAdView = (MpsBannerAdView) findViewById(R.id.mps_ad);
After you have an object of the view just add the following code to load an ad into the banner view:
mpsBannerAdView.displayBannerAd("testbox", page, new MPSBannerAdListener() {
@Override
public void onAdLoaded(@NonNull MPSBannerAdView bannerAdView) {
super.onAdLoaded(bannerAdView);
}
});
Also you can pass additional ad targeting as third parameter to displayBannerAd
function:
Map<String, String> additionalTargeting = new HashMap<>();
additionalTargeting.put("key", "value");
mpsBannerAdView.displayBannerAd("testbox", page, additionalTargeting, new MPSBannerAdListener() {
@Override
public void onAdLoaded(@NonNull MPSBannerAdView bannerAdView) {
super.onAdLoaded(bannerAdView);
}
});
This image shows the displayed banner ad.