Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android admob must have AdActivity declared

Tags:

android

admob

Before writing this question I have checked various questions on Stack Overflow such as:

  • https://stackoverflow.com/questions/10672334/could-not-find-com-google-ads-adactivity-must-have-adactivity-declared-in-the-ma

I have checked the spelling and it seems to be correct.

I also checked the targetSdkVersion is greater than Sdk13. Mine is set too

android:targetSdkVersion="15" />

I checked this question but I am not sure if this is the problem.

  • Adding Admob code to Android giving error: You must have AdActivity declared in AndroidManifest.xml

I have also consulted this particular url

  • Admob Error in Eclipse for android:configChanges

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>

The error message that is returned is a black box where the add should be. And red writing which says You must have AdActivity declared in AndroidManifest.xml with configChanges

like image 460
alex Avatar asked Mar 11 '26 20:03

alex


1 Answers

Your missing android:configChanges attribute in AdActivity, like this:

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

Also your project needs to reference Android SDK 2.2 (API 8) and later.

like image 122
azgolfer Avatar answered Mar 13 '26 10:03

azgolfer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!