+ // Get a handle for the display.
+ Display display = activity.getWindowManager().getDefaultDisplay();
+
+ // Initialize a display metrics.
+ DisplayMetrics displayMetrics = new DisplayMetrics();
+
+ // Get the display metrics from the display.
+ display.getMetrics(displayMetrics);
+
+ // Get the width pixels and the density.
+ float widthPixels = displayMetrics.widthPixels;
+ float density = displayMetrics.density;
+
+ // Calculate the ad width.
+ int adWidth = (int) (widthPixels / density);
+
+ // Get the ad size. This line should be enabled once Firebase Ads is updated to 20.0.0.
+ AdSize adSize = AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(applicationContext, adWidth);
+
+ // Set the ad size on the adView.
+ adView.setAdSize(adSize);
+
+ // Create an ad settings bundle.