How to specify adUnitId programmatically for AdMob?

前端 未结 1 482
隐瞒了意图╮
隐瞒了意图╮ 2020-12-17 14:37

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 ):

相关标签:
1条回答
  • 2020-12-17 15:18

    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);
    
    0 讨论(0)
提交回复
热议问题