开发者

Integrating admob into Android app

开发者 https://www.devze.com 2023-03-12 06:49 出处:网络
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

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_pa开发者_如何学运维rent"
    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!


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);
0

精彩评论

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

关注公众号