0

I have created an application for admob, but I am getting an error. I found an example from Google and I have tried it, but there is a problem when I'm launching the application .

I'm using Android 2.2 API 8. I am able to launch the application, but this block is causing an error.

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

If I change this to

android:configChanges="keyboard|keyboardHidden"

then I am able to launch the application, but there is an error coming on our add field.

you must have adactivity declare in Android Manfiest.xml with config change

Due to this I am not able to show google adds in our application.

Please help me to fix this.

4

3 回答 3

2

我想你只需要按照这个教程。

尤其是您的问题应该与以下几行有关:

适用于 Android 的 Google AdMob 广告 SDK 需要 Android 1.5 或更高版本。确保您拥有最新的 Android SDK 副本并且您正在针对至少 Android v3.2 进行编译(将 default.properties 中的目标设置为 android-13)。

这意味着 minSDK 可以降到 1.5,但您至少必须在 3.2 上编译。

于 2012-04-20T07:49:01.023 回答
0
 - AdActivity.java

package com.android.ads;

import android.app.Activity;
import android.os.Bundle;

import com.google.ads.AdRequest;
import com.google.ads.AdView;

public class AdsActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        AdView adview = (AdView) findViewById(R.id.adView);
        AdRequest re = new AdRequest();
        re.setTesting(true);
        re.setGender(AdRequest.Gender.FEMALE);
        adview.loadAd(re);
    }
}

 - main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        xmlns:ads="http://schemas.android.com/apk/res/com.android.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

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

     <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="Your adunit ID" 
        android:layout_alignParentBottom="true"/>    
</LinearLayout>

Remember Put GoogleMapAdmobSdk.jar after creating libs folder for Configure build path 


Create the attrs.xml in the Values folder

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <declare-styleable name="com.google.ads.AdView">
      <attr name="adSize">
          <enum name="BANNER" value="1"/>
          <enum name="IAB_MRECT" value="2"/>
          <enum name="IAB_BANNER" value="3"/>
          <enum name="IAB_LEADERBOARD" value="4"/>
      </attr>
      <attr name="adUnitId" format="string"/>
  </declare-styleable>
</resources>

 - AndroidManifest

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

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".AdsActivity"
            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>

</manifest>


Your work is done buddy............
于 2012-04-20T08:48:47.373 回答
0

来自 AdMob 文档

您需要将整个活动标签添加到 AndroidManifest.xml

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

请参阅https://developers.google.com/mobile-ads-sdk/docs/android/fundamentals

于 2012-04-20T07:46:38.293 回答