gpt4 book ai didi

java - 如何在我的 Android 应用程序中添加 Admob 广告?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:58:47 26 4
gpt4 key购买 nike

我读过这篇文章http://code.google.com/mobile/ads/docs/android/fundamentals.html ,现在我有了代码

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

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>

但我总是收到消息“您必须在 AndroidManifest.xml 中使用 configChanges 声明 AdActivity”。我哪里弄错了?

最佳答案

如果您使用最新的 admob sdk,您需要像这样定义您的 AdActivity:

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

请注意,某些 configChanges 选项需要更新的 Android SDK 版本(API 级别 11),如您提供的链接中所述,您需要:

Requirements

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).

希望对您有所帮助。

关于java - 如何在我的 Android 应用程序中添加 Admob 广告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8029520/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com