The admob smart_banner is deprecated in java code. But it isn't mark as deprecated in XML.
my xml:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-xxx">
</com.google.android.gms.ads.AdView>
My java:
AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
My question here is, will smart_banner work? Do I have to change my ads code? Am I doing something wrong? Thanks friends.
Accordingly you are not doing anything wrong , smart banner ads are valid ads size ,but the site says you should rather use Adaptive Banner which change the banner size accordingly and are more preferred .
Adaptive banners are the next generation of responsive ads, maximizing performance by optimizing ad size for each device. Improving on smart banners, which only supported fixed heights, adaptive banners let developers specify the ad-width and use this to determine the optimal ad size.
Your java code shows AdSize.SMART_BANNER deprecated because the docs says to use
public static AdSize getCurrentOrientationAnchoredAdaptiveBannerAdSize (Context context, int width)
instead of AdSize.SMART_BANNER , it returns an AdSize with the given width and a Google-optimized height to create a banner ad | this dosen't happens in xml as there's no alternative way also you should use Adaptive Banners which works in simillar ways .
If you want to use it you can use this way of setting adSize
AdSize adSize = getAdSize();
adView.setAdSize(adSize);
and get adSize() as
private AdSize getAdSize() {
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics();
display.getMetrics(outMetrics);
float widthPixels = outMetrics.widthPixels;
float density = outMetrics.density; int adWidth = (int) (widthPixels / density);
return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(this, adWidth); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With