Android 中 Admob 的 XML 或 Java 关键字

发布于 2024-11-01 09:32:16 字数 1874 浏览 2 评论 0原文

我似乎找不到任何关于通过 XML 或 Java 设置 adMob 广告关键字的可靠文档。我已经尝试过线程中看到的方法,但在两个方面都失败了。我对每种情况的失败如下。

当尝试使用 AdView 类中的 setKeywords()、setSearchQuery() 或 requestFreshAd() 方法时,Eclipse 无法识别这些方法是 AdView 类的一部分。我可以不正确地实例化这个类吗?我的java代码如下:

import com.google.ads.AdRequest;
import com.google.ads.AdView;

AdView adView = (AdView)this.findViewById(R.id.adView);
    adView.loadAd(new AdRequest());

如果我尝试调用上述方法(例如 adView.setKeywords() ),Eclipse 无法识别这些方法。我做错了什么?

当我尝试通过 XML 设置关键字时,代码似乎运行正常,但我没有收到任何有效的添加请求。日志返回并显示“无广告可显示”消息。在这种情况下,我不知道我是否只是没有从关键字中获得结果,或者是否没有正确设置关键字字符串。

下面描述了我如何通过 XML 设置关键字:

...in attrs.xml:

<?xml version="1.0" encoding="utf-8"?>
 <resources>
  <declare-styleable name="com.google.ads.AdView">
   <attr name="adSize">
      <enum name="BANNER" value="1"/>
      <enum name="IAB_MRECT" value="2"/>
      <enum name="IAB_BANNER" value="3"/>
      <enum name="IAB_LEADERBOARD" value="4"/>
   </attr>
   <attr name="adUnitId" format="string"/>
   <attr name="test" format="boolean"/>
   <attr name="keywords" format="string"/>
  </declare-styleable>
 </resources>

in layout.xml...

    <com.google.ads.AdView android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_gravity="bottom"
        android:layout_height="wrap_content"
        ads:adUnitId="blahblahblhal"
        ads:adSize="BANNER"
        ads:test="true"
        ads:keywords="farts cheese stink pooper"/>

显然,这些不是我正在使用的关键字,而是我设置关键字的语法和我一直用的一样。

如果没有广告显示,是否是因为我使用了太多关键字、语法不正确,以及如果我想使用短语而不是关键字怎么办?我该怎么做呢?

如果 AdMob 网站上有与此相关的文档,我深表歉意。但如果是这样的话,他们就很难找到了。

谢谢

I can't seem to find any rock solid documentation on setting keywords for adMob ads via XML or Java. I've tried the methods seen in this thread, but have failed in both respects. My failures for each case are below.

When trying to use methods setKeywords(), setSearchQuery(), or requestFreshAd() from the AdView class, it's like Eclipse doesn't recognize that those methods are part of the AdView class. Could I be instantiating this class improperly? My java code is below:

import com.google.ads.AdRequest;
import com.google.ads.AdView;

AdView adView = (AdView)this.findViewById(R.id.adView);
    adView.loadAd(new AdRequest());

If I try to call the aforementioned methods, (eg. adView.setKeywords() ), Eclipse doesn't recognize the methods. What am I doing wrong?

When I attempt to set the keywords via XML, the code seems to run ok, but I don't get any valid requests for an add. The log returns with a "No ad to display" message. In this case, I don't know if I'm just not getting a result from my keywords or if I'm not settings the keyword string correctly.

The following depicts how I'm setting the keywords via XML:

...in attrs.xml:

<?xml version="1.0" encoding="utf-8"?>
 <resources>
  <declare-styleable name="com.google.ads.AdView">
   <attr name="adSize">
      <enum name="BANNER" value="1"/>
      <enum name="IAB_MRECT" value="2"/>
      <enum name="IAB_BANNER" value="3"/>
      <enum name="IAB_LEADERBOARD" value="4"/>
   </attr>
   <attr name="adUnitId" format="string"/>
   <attr name="test" format="boolean"/>
   <attr name="keywords" format="string"/>
  </declare-styleable>
 </resources>

in layout.xml....

    <com.google.ads.AdView android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_gravity="bottom"
        android:layout_height="wrap_content"
        ads:adUnitId="blahblahblhal"
        ads:adSize="BANNER"
        ads:test="true"
        ads:keywords="farts cheese stink pooper"/>

Obviously, these are not the keywords I'm using, but the syntax by which I set the keywords is the same as I've been using.

If there is no ad to display is it because I'm using too many keywords, improper syntax, and what if I want to use a phrase instead of a keyword? How would I go about doing that?

If there is documentation on the AdMob site pertaining to this I apologize. But if so, they made it pretty damn hard to find.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

香橙ぽ 2024-11-08 09:32:16

setKeywordsAdRequest 类的方法,而不是 AdView 的方法。

AdRequest request = new AdRequest();
Set<String> keywords = new HashSet<String>();
keywords.add("keyword1");
keywords.add("keyword2");
request.setKeywords(keywords);
adView.loadAd(request);

setKeywords is a method of the AdRequest class, not AdView.

AdRequest request = new AdRequest();
Set<String> keywords = new HashSet<String>();
keywords.add("keyword1");
keywords.add("keyword2");
request.setKeywords(keywords);
adView.loadAd(request);
柳若烟 2024-11-08 09:32:16

Google 在 Admob SDK 4.1.1 版本中添加了将关键字指定为 XML 属性的功能(请参阅 [1] 中的发行说明)。遗憾的是,它没有记录在案,但在 [2] 中您可以看到 Google 的响应,其中阐明了 XML 属性的名称。正确的属性是“ads:keywords”,它接受以逗号分隔的关键字列表。以下是示例:

<com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            ads:adUnitId="YOUR_PUBLISHER_ID"
            ads:adSize="BANNER"
            ads:loadAdOnCreate="true"
            ads:keywords="keyword1,keyword2,keyword3"
/>

[1] http://code.google.com /mobile/ads/docs/rel-notes.html

[2] http://groups.google.com/group/google-admob-ads-sdk/browse_thread/thread/b9b0b81858234adb

Google added the ability to specify keywords as an XML attribute in version 4.1.1 of the Admob SDK (see Release Notes in [1]). Unfortunately it is not documented, but in [2] you can see a response from Google that clarifies the name of the XML attribute. The correct attribute is "ads:keywords", and it accepts a comma-separated list of keywords. Here is an example:

<com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            ads:adUnitId="YOUR_PUBLISHER_ID"
            ads:adSize="BANNER"
            ads:loadAdOnCreate="true"
            ads:keywords="keyword1,keyword2,keyword3"
/>

[1] http://code.google.com/mobile/ads/docs/rel-notes.html

[2] http://groups.google.com/group/google-admob-ads-sdk/browse_thread/thread/b9b0b81858234adb

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文