尽管在清单中声明了AdActivity错误

时间:2014-02-23 14:15:56

标签: java android eclipse admob google-play-services

我正在尝试通过Google Play服务在Android应用程序中实现Admob。

我已在清单文件中声明了adactivity,但我仍然收到错误:AdActivity with ... not manifest in manifest file。

这是我到目前为止所做的:

xml文件是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".AddActivity" 
android:id="@+id/adView">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

Java文件是:

package com.example.adtesting;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.RelativeLayout;

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

public class AddActivity extends Activity {
    final String adUnitId ="pub-*******";

      private AdView adView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        // create adView
        adView = new AdView(this);
        adView.setAdUnitId(adUnitId);
        adView.setAdSize(AdSize.BANNER);

        //Lookup Linear Layout
        RelativeLayout layout = (RelativeLayout) findViewById(R.id.adView);

        //add AdView to it
        layout.addView(adView);
        //initiate generic request
        AdRequest adRequest = new AdRequest.Builder().build();

        // Load the adView withe the add request
        adView.loadAd(adRequest);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.add, menu);
        return true;
    }

}

清单文件是:

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >


        <meta-data android:name="com.google.android.gms.version" 
    android:value="@integer/google_play_services_version"/>

        <activity
            android:name="com.example.adtesting.AddActivity"
            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.gms.ads.AdActivity" 
        android:configChanges="keyboard|keyboardHidden|orientation|
        screenLayout|uiMode|screenSize|smallestScreenSize"/>
            </application>

    </manifest>

请注意,我引用了Google Play服务SDK。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您已经声明了包裹:

package="com.example.adtesting"

所以你只需要:android:name =“。AddActivity”

    <activity
        android:name=".AddActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>