Please allow adUnitId to be specified in strings.xml and/or MANIFEST

723 views
Skip to first unread message

Mark Carter

unread,
Apr 29, 2011, 10:54:19 PM4/29/11
to google-adm...@googlegroups.com
I would like to be able to do something like:

adUnitId="@string/adUnitId" in the AdView XML element

but this does not seem to work.

Even better, I would like to be able to specify the adUnitId in the Manifest (which was easily possible in the old version of the SDK).

Should be very easy (and standard) to support this.


Mark Carter

unread,
Apr 29, 2011, 10:57:56 PM4/29/11
to google-adm...@googlegroups.com
Note - This is concerning the Android Google Admob SDK (4.0.4)

Neil

unread,
Apr 30, 2011, 7:22:19 AM4/30/11
to google-adm...@googlegroups.com
I would also be very happy to see either of those options.

Neil

seb

unread,
Apr 30, 2011, 5:13:08 PM4/30/11
to Google AdMob Ads Developers
You can do this by specifying the following in the attrs.xml file

<attr name="adUnitId" format="string"/>

and then in your AdView XML view add an attribute as follows

ads:adUnitId="YOUR_ID"

Regards

William Ferguson

unread,
Apr 30, 2011, 7:40:14 PM4/30/11
to Google AdMob Ads Developers
Actually seb,

adUnitId="@string/adUnitId" in the AdView XML element


doesn't seem to work.
Form memory you get a bad AdMobId error in the logs.
I found I needed to specify my Id explicitly in the layout XML, which
is in multiple places for me (to handle rotation etc).

Tim

unread,
Apr 30, 2011, 7:47:26 PM4/30/11
to Google AdMob Ads Developers
We are working on a fix to allow string resources (e.g. "@string/
something") in our XML layouts. It should be available in the next
release.

Thanks,
-Tim



On Apr 30, 4:40 pm, William Ferguson <william.ferguson...@gmail.com>
wrote:

seb

unread,
May 1, 2011, 6:11:17 AM5/1/11
to Google AdMob Ads Developers
On May 1, 12:40 am, William Ferguson <william.ferguson...@gmail.com>
wrote:
William,

You are trying to get the adUnitId from the strings.xml, as I said
trying using the attrs.xml to define the tag, i.e.

attrs.xml file in the res/values directory as follows

<?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"/>
</declare-styleable>
</resources>

and then in your layout xml define your AdView, e.g.

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

The only thing is you'll have to enter the id in multiple places if
you have several AdViews.

One thing to note is that you need to declare the ads namespace in
your layout xml. i.e.

xmlns:ads="http://schemas.android.com/apk/res/
com.yourdomain.yourpackage"

William Ferguson

unread,
May 1, 2011, 12:22:28 PM5/1/11
to Google AdMob Ads Developers
Seb, please read Mark Carter's original post again.

He (as I do) wants to be able to specify the AdMobId in strings.xml
instead of in every layout. Ie

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


William

William Ferguson

unread,
May 1, 2011, 12:23:16 PM5/1/11
to Google AdMob Ads Developers
Thanks Tim, that's good news.

seb

unread,
May 1, 2011, 1:24:21 PM5/1/11
to Google AdMob Ads Developers
Sorry, I've put my goggles on now, and see what he means. :-)

Agreed, it would be useful to have one place to define your id.
Reply all
Reply to author
Forward
0 new messages