gpt4 book ai didi

android admob 必须声明 AdActivity

转载 作者:太空狗 更新时间:2023-10-29 15:48:07 25 4
gpt4 key购买 nike

在写这个问题之前,我检查了 Stack Overflow 上的各种问题,例如:

我检查了拼写,似乎是正确的。

我还检查了 targetSdkVersion 是否大于 Sdk13。我的也设置好了

android:targetSdkVersion="15" />

我检查了这个问题,但我不确定这是否是问题所在。

我也引用过这个特定的url


package com.example.advert;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.support.v4.app.NavUtils;
import com.google.ads.*;
public class MainActivity extends Activity {
private AdView adView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);



String MY_AD_UNIT_ID = "a15000820551daa";

// Create the adView
adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);

// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);

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

// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());





}

@Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}




}

AndroidManifest.xml

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.advert"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<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"

></activity>
</application>

</manifest>

返回的错误消息是一个黑框,其中应添加。红色文字表示您必须在 AndroidManifest.xml 中使用 configChanges 声明 AdActivity

最佳答案

AdActivity 中缺少的 android:configChanges 属性,如下所示:

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

您的项目还需要引用 Android SDK 2.2 (API 8) 及更高版本。

关于android admob 必须声明 AdActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11493880/

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