bobbyrne01
bobbyrne01

Reputation: 6745

Integrating admob into Android app

Been having some trouble trying to integrate the admob sdk into my application to display ads. Im using the AdmobSDK version 4.1.0. I've read loads of posts and there seems to be lacking some decent documentation and many discussions on the topic including http://groups.google.com/group/google-admob-ads-sdk/browse_thread/thread/3b885d3fe5bb21a5?pli=1 So far my layout is..

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/scroll" 
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<LinearLayout
    android:id="@+id/linear" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:focusable="true"
    android:focusableInTouchMode="true">

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

</LinearLayout>
</ScrollView>

my androidmanifest.xml contains...

<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"></activity>

<meta-data android:value="MY_PUBLISHER_ID" android:name="ADMOB_PUBLISHER_ID"></meta-data>

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>

EDIT, UPDATE:

Ok i seem to have gotten admob working on my HTC by adding,

AdView ad = (AdView) findViewById(R.id.ad);
AdRequest r = new AdRequest()
r.addTestDevice("X3XFX518X7DE1FD879XA5XXAX1AX8BXX");
ad.loadAd(r);

however i only recieve a test banner, stating im ready to explore the google app galaxy. When i remove the "addTestDevice" method, the banner/ad does not show up atal and in the log i recieve, "ad not recieved due to lack of inventory" .. Anyone sheed some light on this?

thanks for the help so far!

Upvotes: 0

Views: 3767

Answers (1)

Haphazard
Haphazard

Reputation: 10948

To your comment, I use this and it works quite well for me. The size is the second param of the AdView constructor.

ad = new AdView(this, AdSize.BANNER, "<ID>");
LinearLayout layout = (LinearLayout) findViewById(R.id.main_admob_layout);
// Add the adView to it
layout.addView(ad);
AdRequest request = new AdRequest();
request.setTesting(TESTING_MODE);
ad.loadAd(request);

Upvotes: 1

Related Questions