📪Banner Ad
Below are the steps to load and render a banner Ad on your app
Create your
AdRequestConfigurationas per the below format
AdRequestConfiguration.Builder configuration = AdRequestConfiguration.Companion.builder(context, "Your_placement_name");val configuration = AdRequestConfiguration.builder(context, "Your_placement_name")Call
loadAd()method as per below format
AdSterAdLoader.Companion.builder().withAdsListener(new MediationAdListener() {
@Override
public void onBannerAdLoaded(@NonNull MediationBannerAd ad) {
super.onBannerAdLoaded(ad);
// Show banner ad here
}
@Override
public void onFailure(@NonNull AdError adError) {
// Handle failure here
}
}).withAdsEventsListener(new AdEventsListener() {
@Override
public void onAdClicked() {
//Handle ad click here
}
@Override
public void onAdImpression() {
//Handle ad impression here
}
@Override
public void onAdRevenuePaid(double revenue, @NotNull String adUnitId,@NotNull String network) {
// Callback which provides revenue and the network which provided it
}
}).build().loadAd(configuration.build());AdSterAdLoader.builder().withAdsListener(object : MediationAdListener() {
override fun onBannerAdLoaded(ad: MediationBannerAd) {
super.onBannerAdLoaded(ad)
// Show banner ad here
}
override fun onFailure(adError: AdError) {
// Handle failure here
}
}).withAdsEventsListener(object : AdEventsListener() {
override fun onAdClicked() {
//Handle ad click here
}
override fun onAdImpression() {
//Handle ad impression here
}
override fun onAdRevenuePaid(revenue: Double, adUnitId: String, network: String) {
// Callback which provides revenue and the network which provided it
}
}).build().loadAd(configuration.build())Inside the
onBannerAdLoadedcallback method invokegetView()method ofMediationnBannerAdobject to add an AdSter banner view to the given layout as shown below
container.removeAllViews();
container.addView(ad.getView());Call
MediationBannerAd.destroy()When activity/fragment is destroyed or detached.
Last updated
Was this helpful?