Android AdMob example

2019-04-02 21:05发布

问题:

I downloaded example code of an Android project featuring AdMob ads from here. In the picture, the ad says "AdMob Test Android Web Ad", but when I run the code, I sometimes see an actual ad and sometimes see nothing. Why?

回答1:

Ensure that test mode is enabled on emulator. Seems like the code in the link does not have it's test mode enable.

Ads do not run immediately after launching the application. It would take a couple of seconds(up to 10secs, depending on your network speed) before being able to receive an advertisement from Admob.

Try something like this in your onCreate().

    adView = new AdView(this, AdSize.BANNER, "a9876sf98dfg");        
    RelativeLayout layout = (RelativeLayout)findViewById(R.id.ad);        
    layout.addView(adView);
    AdRequest request = new AdRequest();
    request.setTesting(false);
    adView.loadAd(request);

EDIT (from the comments): Follow the instructions on edumobile.org/android/android-development/admob-manager, but add the line "android:id="@+id/linearLayout" to the LinearLayout part of main.xml.



回答2:

The sample code probably isn't in test mode. To enable test mode follow the instructions here: http://code.google.com/intl/de-DE/mobile/ads/docs/bestpractices.html#testmode



标签: android admob