AdMob Ads Not Showing(AdMob 广告未显示)
问题描述
因此,我使用 Play Services SDK 实现了 AdMob 广告.我已经按部就班"做了所有事情,但广告不会显示.
So, I implemented AdMob ads with the Play Services SDK. I've done everything 'by the book', but the ads won't show.
如果我将 AdView 背景设置为白色,它会显示空白而不是广告.我正在使用片段,但我将 AdView 放在 activity_main.xml
中(尽管在片段中我在底部设置了 60dp 的边距)
If I set the AdView background to white, it shows the white space but not the Ad.
I'm using Fragments, but I'm putting the AdView in the activity_main.xml
(although in the fragments I've set a margin of 60dp at the bottom)
这是我的 onCreate
代码(带有实际代码和测试"代码)
Here's my onCreate
code (with the actual code and the 'testing' code)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
drawer.openDrawer(Gravity.LEFT);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("Device_ID")
.build();
adView.loadAd(adRequest);
}
这是我的 activity_main.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.MainActivity">
<RelativeLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/adView" >
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="Unit_ID"
ads:adSize="BANNER"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<fragment
android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name="com.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer" />
我错过了什么?
推荐答案
我想除了你已经拥有的这个块:
I think in addition to this block that you already have:
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("Device_ID")
.build();
...你错过了这样的东西:
...You are missing something like this:
AdView adView = (AdView) this.findViewById(R.id.adView);
adView.loadAd(adRequest);
这是完整的图片:
xml 文件中的内容:
what is in xml file:
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adUnitId="your ad unit id"
ads:adSize="BANNER"/>
onCreate 中有什么:
what is in onCreate:
AdRequest adRequest = new AdRequest.Builder()
.build();
AdView adView = (AdView) this.findViewById(R.id.adView);
adView.loadAd(adRequest);
请注意,上面的代码是用于生产的.您必须使用测试设备 ID 进行测试以避免 AdMob 处罚.
Please note the code above is for production. You must use test device id for testing in order to avoid AdMob penalties.
这篇关于AdMob 广告未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:AdMob 广告未显示
基础教程推荐
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 在螺旋中写一个字符串 2022-01-01