πŸ“ͺNative Ad

Below are the steps to load and show a native ad on your app

  1. Create your AdRequestConfiguration as per the below format

AdRequestConfiguration.Builder configuration = AdRequestConfiguration.Companion.builder(context, "Your_placement_name");
  1. Call loadAd() method as per below format

AdSterAdLoader.Companion.builder().withAdsListener(new MediationAdListener() {
    @Override
    public void onNativeAdLoaded(@NonNull MediationNativeAd ad) {
        super.onNativeAdLoaded(ad);
        //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) {
        // Callback which provides revenue and the network which provided it
    }
}).build().loadAd(configuration.build());
  1. Inside the onNativeAdLoaded callback method use MediationNativeAd object to display native ad on your defined layout.

  2. Define your native ad layout, below is just an example of a layout

  1. The above sample layout can be used with the MediationNativeAd object to render an ad as shown in the below example

circle-info

Make sure to call trackViews and setNativeAd method before adding MediationNativeAdView to the container.

circle-info
  1. Call MediationNativeAd.destroy when activity or fragment is getting destroyed.


Native Ad in Dynamic Layout

circle-info

Last updated