android admob集成问题 - 不允许使用字符串类型

时间:2012-08-18 04:56:21

标签: android admob

我正试图第一次整合admob。我遵循了文档规则here,我看到了several related pages,但我似乎仍然做错了。
我使用的是GoogleAdMobAdsSdk-6.1.0.jar,以及android sdk 13(Android 3.2)。

我从各种来源中找到了我发现的一些东西。

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="13" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<activity android:name="com.google.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScre‌​enSize"  />

在我的AndroidManifest.xml中。

我包括

target=android-13

在我的project.properties中。

以上配置无法编译。我在eclipse中遇到错误(版本:4.2.0),说明如下:

error: Error: String types not allowed (at 'configChanges' with value 'keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScre‌​enSize'

如果我将其改为旧式

android:configChanges="keyboard|keyboardHidden|orientation"

该项目编译得很好,但是当我进入我的活动时,我遇到了以下问题:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/Aqua"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/adLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </LinearLayout>

</LinearLayout>

我的活动中的代码如下所示:

public class TutorialActivity extends Activity {

    private static final String PUBLISHER_ID = "blah"; //omitted
    private AdView adView;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.tutorial_layout);
        AdRequest request = new AdRequest();
        request.addTestDevice("what i believe is my device id");

        adView = new AdView(this, AdSize.BANNER, PUBLISHER_ID);

        LinearLayout layout = (LinearLayout) findViewById(R.id.adLayout);
        layout.addView(adView);
        adView.loadAd(request);
    }

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

}

当我运行此代码并导航到我的活动时,我会看到屏幕顶部看起来像我期望的广告框,内部是以下文字:     您必须在AndroidManifest.xml中使用configChanges声明AdActivity。

我是一个迷茫的人。这是我在将应用程序发布到谷歌应用程序商店之前在我的应用程序中包含的最后一件事,并且非常感谢任何建议或帮助。 如果我遗漏了任何东西,我会道歉。

1 个答案:

答案 0 :(得分:8)

我遇到了同样的问题。我会告诉你我做了什么。

右键点击eclipse中的项目文件夹

  • -properties
  • -choose android
  • - 选择固件3.2或更高版本

然后在清单

中使用它
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"

那就是