我有我的AdMob代码落实到我的XML文件是这样的:Android的AdMob的-onReceivedAd击中,但没有广告显示
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="30dp"
android:layout_height="30dp"
ads:adUnitId="???????"
ads:adSize="BANNER"
ads:loadAdOnCreate="false"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
在我的我的活动的onCreate方法:
// load ads
AdView adView = (AdView)findViewById(R.id.adView);
AdRequest request = new AdRequest();
//request.setTesting(true);
adView.setAdListener(new AdListener() {
public void onReceiveAd(Ad arg0) {
// TODO Auto-generated method stub
}
public void onPresentScreen(Ad arg0) {
// TODO Auto-generated method stub
}
public void onLeaveApplication(Ad arg0) {
// TODO Auto-generated method stub
}
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
// TODO Auto-generated method stub
}
public void onDismissScreen(Ad arg0) {
// TODO Auto-generated method stub
}
});
adView.loadAd(request);
我可以在onReceivedAd侦听器中放置一个断点,并且在运行我的应用程序时总是停在那里;然而,没有任何显示。我的AdMob页面也会显示请求。我尝试了进入和退出测试模式(参见上面的注释行),结果相同。另外,为避免任何人询问,我的广告:adUnitId =“????”设置为在AdMob网站上我的应用旁边找到的Publisher ID
。
任何人都有如何从这里调试的建议?
你为什么不把一些代码(和它一个破发点)内的'公共无效onFailedToReceiveAd(广告为arg0,错误码ARG1)'和看看是否有错误接收广告? –
@Aleks - 我在每个侦听器方法中都有一行代码(只是int i = 0; i ++)。唯一触及的断点是onReceivedAd - 其他3个总是跳过。 – bugfixr
@mibollma - 你是对的人,我没有注意到我把广告放在了我的标签主机中。我在顶部制作了一个LinearLayout,然后将adview和选项卡主机移到该主题中,并且它可以正常工作。通过一切手段,添加一个答案,以便您可以获得信用:) – bugfixr