π¨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)
AdRequestConfiguration.Builder configuration = AdRequestConfiguration.Companion.builder(context, "Your_placement_name");val configuration = AdRequestConfiguration.builder(context, "Your_placement_name")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);
}fun getAdSize(): Int {
val displayMetrics = getResources().displayMetrics
var adWidthPixels = displayMetrics.widthPixels
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowMetrics = this.windowManager.currentWindowMetrics
adWidthPixels = windowMetrics.bounds.width()
}
val density = displayMetrics.density
return (adWidthPixels / density).toInt()
}Last updated