Reputation: 1557
Is Java code required for AdMob ads? On developers website they use java code, but I tried to load ads just with xml code and it works, just I'm not sure will clicks count. I also noticed that when I was using java code too, that 2 ads were displayed, one behind another.
I'm now using just this:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
.
.
.
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="..."
ads:adSize="SMART_BANNER"
ads:loadAdOnCreate="true" />
Is this enough or should I also use java code? Here id is not required at all as much as I can see.
Upvotes: 1
Views: 339
Reputation: 43023
You don't need to have any Java code to run AdMob adds from com.google.ads.AdView
(SDK version up to 6.4.1). Your code will function correctly without it if you use ads:loadAdOnCreate="true"
.
You should see the test ads if your using the test mode or the reel ads if you don't. If you see them, it all works correctly.
Upvotes: 2
Reputation: 146
Java code is not required to use com.google.ads.AdView
but you must include your ad unit ID in order for clicks to be counted. However, com.google.ads.AdView
is part of the older AdMob Android API. To use the Mobile Ads API in Google Play services you must use Java code. The documentation states:
The five lines of code it takes to add a banner:
Upvotes: 1