🎨Adaptive Banner Ad (Only for GAM)

Below are the steps to pass predefined custom targeting value in ad request for GAM (Supported by all ad formats)

  1. Create your AdRequestConfiguration as per the below format

AdRequestConfiguration.Builder configuration = AdRequestConfiguration.Companion.builder(context, "Your_placement_name");
  1. Adding preferred adaptive ad type to AdRequest

chevron-rightInline adaptive banner adhashtag
configuration.addInlineAdaptiveBannerAdSize(width, maxHeight);
chevron-rightCurrent orientation inline adaptive banner adhashtag
configuration.addCurrentOrientationInlineAdaptiveBannerAdSize(width);
chevron-rightAnchored adaptive banner adhashtag
configuration.addAnchoredAdaptiveBannerAdSize(getAdSize());
circle-info

Use the below code to get ad size for anchored adaptive banner ad request :

private Integer getAdSize() {
    DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
    int adWidthPixels = displayMetrics.widthPixels;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        WindowMetrics windowMetrics = this.getWindowManager().getCurrentWindowMetrics();
        adWidthPixels = windowMetrics.getBounds().width();
    }

    float density = displayMetrics.density;
    return (int) (adWidthPixels / density);
}
  1. Call loadAd() method as per below format

  1. Inside the onBannerAdLoaded callback method invoke getView() method of MediationnBannerAd object to add an AdSter banner view to the given layout as shown below

  1. Call MediationBannerAd.destroy() When activity/fragment is destroyed or detached.

Last updated