开发者

getting started with admob for android - confused about documentation

I just started looking into putting Admob ads into the android app I'm building. So far, no good. I've been following the example in the AdMod_Android_SDK_Instructions.pdf that I downloaded from the adMob website, but am confused. On page 7 I see the import statements refer to the package as com.admob.android.ads - but in the SDK I downloaded, the package is com.google.ads - is this a leftover from before google acquired admob? It then goes on to call the method adView.requestFreshAd(); - which does not exist in the latest code. Plea开发者_运维技巧se can someone help me out with some code that actually works? My specific errors from logcat are:

AdView missing required XML attribute adUnitId.

... then after I call adView.loadAd(new AdRequest()); i get:

Invalid unknown request error: Cannot determine request type.  Is your ad unit Id correct?
onFailedToReceiveAd(Invalid Google Ad request).

Any help, much appreciated! Thanks.


As of 4.1.0,

mob1lejunkie is perfectly right, you can remove

  • attrs.xml
  • background, primarytextcolor, secondarytextcolor attributes (and define them from admob web site on the manage setting tab of your app)
  • remove the name space xmlns:myapp from your main layout in your xml file and replace it by xmlns:ads (take care here !! The new xmlns is not in /apk/res but apk/lib )
  • change the namespace of adUnitID and adSize in the adView xml snippet

so here is a working xml snippet with admob 4.1.0 :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="fill_parent"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads">

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

Isn't it a bit light from google to ask devs to put in place a new code and use a librairy that is not yet documented by google themselves ? It reminds me of the adwhirl adventure...

Nevertheless, I must say I am glad google put that in place and remove the attrs.xml stuff. It is much easier to use admob with project inheritance in android.

Also, with respect to using multiple adviews in a project, please note that with this release, it is now possible to add you admob id in the strings.xml file of your application as requested on this thread : http://groups.google.com/group/google-admob-ads-sdk/browse_thread/thread/c57917b4491a0c1

Just put it this way in your xml layouts for all your adviews :

ads:adUnitId="@string/admob_unit_id"

and then

<string name="admob_unit_id">a14d7f7d2180609</string>

in your strings.xml file and all other localized versions of this file. This will give you a single centralized location to enter your admob id in all your views.

Great release indeed.

Regards, Steff


I had the similar issue with 4.1.0 and it turns out Admob documentation (as of 15th May) is out of date.

attrs.xml is no longer needed and the namespace in the layout needs to be

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads

rater then the old

xmlns:ads="http://schemas.android.com/apk/res/com.your.packagename


Seems like the PDF is outdated.

Try reading Google AdMob Ads Android Fundamentals


This page helped me with with placing an ad in the XML layout: http://code.google.com/mobile/ads/docs/android/banner_xml.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜