如何获得谷歌的例子code使用的是Android设备的AdMob 4.1.0工作 [英] How to get Google's example code working for AdMob 4.1.0 using an Android device

查看:207
本文介绍了如何获得谷歌的例子code使用的是Android设备的AdMob 4.1.0工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用XML来的横幅广告添加到我的应用程序。要了解如何做到这一点,我在谷歌AdMob的广告阅读Android的横幅XML教程。甚至还有例如code。但是,例如项目不显示我的设备(摩托罗拉XT720)的广告。我得到了LogCat中相关的什么都没有。

I want to use xml to add a banner ad to my app. To understand how to do this, I read through the Google AdMob Ads Android Banner XML tutorial. There's even example code. However, the example project doesn't display ads on my device (a Motorola xt720). I get nothing relevant in LogCat.

如果我去项目设置和删除4.0.4罐子,并添加4.1.0罐子,我下载了Android SDK和AVD管理器(下载谷歌Admob的广告SDK包,修订版2,该文件是 Android的SDK-linux_86 /演员/谷歌/ admob_ads_sdk / GoogleAdMobAdsSdk-4.1.0.jar ),然后我得到这个在LogCat中。

If I go to project settings and remove the 4.0.4 jar and add the 4.1.0 jar that I downloaded with Android SDK and AVD Manager (downloaded "Google Admob Ads Sdk package, revision 2" and the file is android-sdk-linux_86/extras/google/admob_ads_sdk/GoogleAdMobAdsSdk-4.1.0.jar), then I get this in LogCat.

ERROR /广告(4486):缺少AD浏览   需要XML属性adSize。

ERROR/Ads(4486): AdView missing required XML attribute "adSize".

信息/广告(4486):要在获得测试广告   该装置,通话   adRequest.addTestDevice(00000000000000000000000000000000);

INFO/Ads(4486): To get test ads on this device, call adRequest.addTestDevice("00000000000000000000000000000000");

我做出的改变:

    AdRequest adRequest = new AdRequest();
    adRequest.addTestDevice("00000000000000000000000000000000");
    adView.loadAd(adRequest);

而现在我得到这样的:

And now I get this:

ERROR /广告(5018):AD浏览报缺少必需的XML属性adSize

ERROR/Ads(5018): AdView missing required XML attribute "adSize".

WARN /广告(5018):无效的未知请求错误:无法确定请求类型。是您的广告单元ID是否正确?

WARN/Ads(5018): Invalid unknown request error: Cannot determine request type. Is your ad unit id correct?

信息/广告(5018):onFailedToReceiveAd(无效的谷歌广告请求)

INFO/Ads(5018): onFailedToReceiveAd(Invalid Google Ad request.)

如果我修改的main.xml修复广告:adUnitId 是值我在我的AdMob帐户,我仍然得到同样的错误。正如你所看到的,我设置我的adSize:

If I edit main.xml to fix the ads:adUnitId to be the value I have in my admob account, I still get the same error. As you can see, I am setting my adSize:

<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adUnitId="000000000000000"
    ads:adSize="BANNER" />


因此​​,在总结:


So in summary:

  • 我固定的库版本
  • 在我加入我的测试设备
  • 在我设定我的广告:adUnitId

不过,我仍然得到 AD浏览报缺少必需的XML属性adSize

我是什么做错了吗?

推荐答案

有一些变化的方式Admob的工作在版本4.1.0

There are some changes to the way Admob works in version 4.1.0

有一个关于谷歌论坛一个讨论关于这个问题,以及如何他们还没有更新的文档。

There's a discussion on Google Groups about this issue and how they haven't updated the documentation.

谷歌员工蒂姆贴:

1)删除attrs.xml(或者,如果你需要它自己的自定义属性,删除相关AdViews的部分)。

1) Remove attrs.xml (or if you need it for your own custom attributes, remove the parts related to AdViews).

2)从的xmlns更改您的布局命名空间:广告=htt​​p://schemas.android.com/apk/res/com.your.packagename的xmlns:广告=htt​​p://schemas.android.com/apk/lib/com.google.ads

一旦你取得了这两个变化(以及你已经取得的其他更改),你现在应该看到的广告。

Once you have made those two changes (along with the other changes you already made), you should now see an ad.

这篇关于如何获得谷歌的例子code使用的是Android设备的AdMob 4.1.0工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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