Android AdMob 示例 [英] Android AdMob example

查看:24
本文介绍了Android AdMob 示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 在这里.在图片中,广告上写着AdMob Test Android Web Ad",但是当我运行代码时,我有时会看到一个实际的广告,有时什么也看不到.为什么?

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?

推荐答案

确保在模拟器上启用了测试模式.似乎链接中的代码没有启用它的测试模式.

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

启动应用程序后,广告不会立即运行.需要几秒钟(最多 10 秒,具体取决于您的网络速度)才能接收来自 Admob 的广告.

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.

在你的 onCreate() 中尝试这样的操作.

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

编辑(来自评论):按照 edumobile.org/android/android-development/admob-manager 上的说明操作,但将android:id="@+id/linearLayout" 行添加到 main 的 LinearLayout 部分.xml.

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.

这篇关于Android AdMob 示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆