googleads / googleads-mobile-android-examples

googleads-mobile-android
Apache License 2.0
1.68k stars 1.86k forks source link

required xml attribute adsize was missing #386

Open bolds07 opened 2 years ago

bolds07 commented 2 years ago

There is a major conflict between admob documentation and admob sdk itself.

Don't take me wrong, I know exactly how to place ads in my apps and I've it working fine for a very long time, but it bugs me off that the documentation states something that clearly doesn't work.

on https://developers.google.com/admob/android/banner it is said:

Warning: Make sure you set the ad size and ad unit ID in the same manner (i.e. set both in XML or both programmatically).

I've never understood why to place such a stupid restriction in the library, but lets just acept it.

The short sentence clearly says that adunit_id and adsize must be set in the same portion of code... NOT SAYING ANYTHING ELSE ABOUT THE OTHER FIELDS

So anyone can conclude from this short sentence that one can declare the adview like:

<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/basicBannerAdview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

and later on in the code do:

    final AdView bannerAdView = findViewById(R.id.basicBannerAdview);
                 bannerAdView.setAdSize(AdSize.BANNER);
                bannerAdView.setAdUnitId("ca-app-pub-2944323778834513/2840086720");
                bannerAdView.loadAd(AdMobRequestUtil.buildAdRequest(loc, Collections.emptySet()).build());
                 bannerAdView.resume();
                bannerAdView.setVisibility(View.VISIBLE);

this is a very simple code, that should work fine according to the documentation. BUT IT DOESN'T

and this has been like this since i started used admob or at least 3 years ago... so guys could you please fix the documentation page?

rannlangel commented 6 months ago

<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto" android:id="@+id/basicBannerAdview" android:layout_width="match_parent" android:layout_height="wrap_content" />

rannlangel commented 6 months ago
final AdView bannerAdView = findViewById(R.id.basicBannerAdview);
             bannerAdView.setAdSize(AdSize.BANNER);
            bannerAdView.setAdUnitId("ca-app-pub-2944323778834513/2840086720");
            bannerAdView.loadAd(AdMobRequestUtil.buildAdRequest(loc, Collections.emptySet()).build());
             bannerAdView.resume();
            bannerAdView.setVisibility(View.VISIBLE);