I\'m trying to set adUnitId programmatically to ads from the new Google Play services (old AdMob).
I have this in XML (used in an
):
The method loadAd()
checks if (mAdView.getAdSize() == null || mAdView.getAdUnitId() == null)
when loadAd happens.
Try logging the boolean output of (mAdView.getAdSize() == null || mAdView.getAdUnitId() == null)
before calling loadAd to determine its state:
mAdView = new AdView(this);
mAdView.setAdSize(AdSize.BANNER);
mAdView.setAdUnitId(AD_UNIT_ID);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
if(mAdView.getAdSize() != null || mAdView.getAdUnitId() != null)
mAdView.loadAd(adRequest);
// else Log state of adsize/adunit
((LinearLayout)findViewById(R.id.adView)).addView(mAdview);