简体   繁体   中英

How to set Smart Banner for Android app?

How can I get "smart banner" in spite of simple "banner" in my android app? . I have tried the following code but in vain. It is not showing any banner instead.

    AdView adView = new AdView(this);
    adView.setAdSize(AdSize.SMART_BANNER);
    adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
    mAdView = findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

The AdView that you are setting Size and UnitID on is not the AdView that you are calling loadAd on. You are setting the ad info on an AdView that you instantiating in code, and then calling loadAd on a view that you are referencing from XML.

mAdView = findViewById(R.id.adView);
mAdView.setAdSize(AdSize.SMART_BANNER);
mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");

AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM