Android AdMob example

2019-04-02 21:26发布

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?

标签: android admob
2条回答
放我归山
2楼-- · 2019-04-02 21:38

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.

查看更多
劳资没心,怎么记你
3楼-- · 2019-04-02 21:47

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

查看更多
登录 后发表回答