如何使用 Android 设备让 Google 的示例代码适用于 AdMob 4.1.0 [英] How to get Google's example code working for AdMob 4.1.0 using an Android device

查看:14
本文介绍了如何使用 Android 设备让 Google 的示例代码适用于 AdMob 4.1.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 xml 向我的应用程序添加横幅广告.为了了解如何执行此操作,我阅读了 Google AdMob Ads Android Banner XML教程.甚至还有示例代码.但是,示例项目不会在我的设备(摩托罗拉 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 jar 并添加我使用 Android SDK 和 AVD Manager 下载的 4.1.0 jar(下载Google Admob Ads Sdk 包,修订版 2"并且文件是 android-sdk-linux_86/extras/google/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.

错误/广告 (4486):缺少 AdView必需的 XML 属性adSize".

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

INFO/Ads(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);

现在我明白了:

错误/广告 (5018):AdView 缺少必需的 XML 属性adSize".

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

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

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

INFO/Ads(5018):onFailedToReceiveAd(无效的 Google 广告请求.)

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

如果我编辑 main.xml 以将 ads: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" />

<小时>

总之:

  • 我修复了库版本
  • 我添加了我的测试设备
  • 我设置了我的广告:adUnitId

但我仍然得到 AdView 缺少必需的 XML 属性adSize"

我做错了什么?

推荐答案

Admob 在 4.1.0 版本中的工作方式发生了一些变化

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

关于 Google 网上论坛的讨论关于这个问题以及他们如何没有更新文档.

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

Google 员工 Tim 发布:

Google employee Tim posted:

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:ads="http://schemas.android.com/apk/res/com.your.packagename" 更改为 xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

2) Change the namespace in your layout from xmlns:ads="http://schemas.android.com/apk/res/com.your.packagename" to xmlns:ads="http://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.

这篇关于如何使用 Android 设备让 Google 的示例代码适用于 AdMob 4.1.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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