Kind of a strange issue here: Whenever I set test mode via xml, I receive the expected test ads in my emulator. However, when I try to do the same programmatically, I seem to get real ads. According to the Admob documentation, these two methods should be equivalent, no? Here is my xml code:
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxxx"
ads:loadAdOnCreate="true">
</com.google.ads.AdView>
And here is the relevant Java code:
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
}
As mentioned before, if I insert the line ads:testDevices=”TEST_EMULATOR, TEST_DEVICE_ID” into the above xml code, I get the test ad just fine. Any ideas?
I believe you have to call .loadAd(adRequest) on the AdView object.
See Google’s AdMob documentation here
In the Adding a com.google.ads.AdView section.