📪Carousel Native Ad
Below are the steps to load and show multiple native ads 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 onCarouselNativeAdLoaded(@NonNull MediationCarouselNativeAd ad) {
// To get the ads
for (MediationNativeAd nativeAd : ad.getAds()) {
displayNativeAd(nativeAd);
//Show native ad here
}
}
@Override
public void onFailure(@NonNull AdError adError) {
//Handle failure callback 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, @NotNull String currency, @NotNull PrecisionType precisionType) {
// Callback which provides revenue and the network which provided it
}
}).build().loadAd(configuration.build());Inside the
onNativeAdLoadedcallback method useMediationNativeAdobject to display native ad on your defined layout.Define your native ad layout, below is just an example of a layout
The above sample layout can be used with the
MediationNativeAdobject to render an ad as shown in the below example
Call
MediationNativeAd.destroywhen activity or fragment is getting destroyed.
Last updated
Was this helpful?