如何显示AdMob横幅?

时间:2011-11-07 10:48:42

标签: java android admob

我有AdMob广告的应用程序。我创建了一个帐户并拥有application_id。没关系,应用程序发送服务器请求,服务器修复它。但是应用程序没有向我展示横幅。我的代码:

main.xml中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/linear"
    android:orientation="vertical" >
</LinearLayout>

的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.nda.ad"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".AdmobActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.google.ads.AdActivity" 
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>  
    </application>

</manifest>

我的活动代码:

package com.nda.ad;

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

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

public class AdmobActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        LinearLayout layout = (LinearLayout)findViewById(R.id.linear);

        // Create the adView
        // Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID

        AdView adView = new AdView(this, AdSize.BANNER, "a14eb6c98335a35");

        // Add the adView to it
        layout.addView(adView);

        // Initiate a generic request to load it with an ad
        AdRequest request = new AdRequest();
        request.setTesting(true);

        adView.loadAd(request); 
    }
}

我在哪里犯了错误?

0 个答案:

没有答案