Android AdMob example(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 示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android AdMob 示例


- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01