如何添加Admob的广告在我的Andr​​oid应用程序? [英] How to add Admob advertising in my Android application?

查看:142
本文介绍了如何添加Admob的广告在我的Andr​​oid应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过这篇文章的http:// code.google.com /移动/广告/文档/安卓/ fundamentals.html ,现在我有code

I have read this article http://code.google.com/mobile/ads/docs/android/fundamentals.html, and now I have the code

package com.nda.admob;

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.util.AttributeSet;
import android.widget.LinearLayout;

public class AdMobTestingActivity extends Activity {
    /** Called when the activity is first created. */
    AdView adView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        adView = new AdView(this, AdSize.BANNER,  "a14eb6c98335a35");
        LinearLayout l=(LinearLayout)findViewById(R.id.linear);
        l.addView(adView);

        AdRequest request = new AdRequest();
        adView.loadAd(request);
    }
}

和$ C $下AndroidManifest:

And code for AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.nda.admob"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".AdMobTestingActivity"
                  android:label="@string/app_name">
            <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"/>       
    </application>
        <uses-sdk android:minSdkVersion="3" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>

不过,我有消息您必须AdActivity在AndroidManifest.xml中宣布与configChanges始终。我在哪里出错了?

But I have the message "You must have AdActivity declared in AndroidManifest.xml with configChanges" always. Where have I made mistake?

推荐答案

如果您使用的是最新的AdMob的SDK,你需要这样定义你的AdActivity:

If you are using the latest admob sdk, you need define your AdActivity like this:

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

请注意,某些configChanges选项需要一个更高的Andr​​oid SDK版本(API等级11),因为它是在链路说你提供的,你需要:

Note that some configChanges option requires a later Android SDK version (API Level 11), As it is stated in the link your provided, you need:

要求

在谷歌的AdMob广告SDK为Android所需的Andr​​oid 1.5或更高版本。请确保您有Android SDK的最新副本,并且你对编译至少的Andr​​oid V3.2(套目标default.properties到Android-13)。

The Google AdMob Ads SDK for Android requires Android 1.5 or later. Make sure you have the latest copy of the Android SDK and that you're compiling against at least Android v3.2 (set target in default.properties to android-13).

希望有帮助。

这篇关于如何添加Admob的广告在我的Andr​​oid应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆