安卓:AdMob无法工作

10

我的应用中AdMob无法显示。每次调用loadAd(..)时,我都会得到以下错误:

请求资源0x7f0b000e失败,因为它是复合的。找不到Google Play服务资源。请检查项目配置以确保包含这些资源。获取广告响应时出现问题。错误码:1

我花了好几个小时搜索解决此问题的方法,但没有找到适用于我的任何东西!我已下载最新版本的Google Play服务并将其添加为库到我的项目首选项中。

这是我的代码:

Activity:

public class WelcomeActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.activity_welcome);

        // Look up the AdView as a resource and load a request.
        AdView adView = (AdView) this.findViewById(R.id.welcomeAdView);

        AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
        adRequestBuilder.addTestDevice("************"); 
        adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
        AdRequest adRequest = adRequestBuilder.build();
        adView.loadAd(adRequest);
    }

}

布局XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res/xx.xx"
    android:id="@+id/container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context="xx.xx.WelcomeActivity" >

.... other layout stuff .....

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true" >

    <com.google.android.gms.ads.AdView
        android:id="@+id/welcomeAdView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="pub-***************" />
</RelativeLayout>

</RelativeLayout>

AndroidManifest.xml:

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

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Holo.Light" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:name="xx.xx.WelcomeActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        ... some more activities ...
        <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" >
        </activity>
    </application>

</manifest>

你是否正在使用 webViewInstance 并且已经调用了一些方法,例如 .pauseTimers() 或者其他暂停主 UI 执行的类似方法? - nKn
我没有看到代码/布局方面的任何问题。我建议您尝试创建一个不同的广告UnitId。 - Libin
@Libin:我创建了一个新的广告UnitID,现在它可以工作了!谢谢!请把你的评论作为答案发布,我会奖励它的赏金 :) - Markus
@ Markus - 已添加为答案 :) - Libin
我遇到了同样的问题。如果我添加别人的单元ID,它可以工作,但是使用我的单元ID就无法工作。我正在使用NativeExpressAdView。 - Ak9637
7个回答

10

我没有发现你的代码/布局有任何问题。问题可能出在 广告单元ID 上。

我建议你尝试创建一个不同的 广告单元ID

希望它有效。


嗨,我有完全相同的问题。但是我该如何创建新的广告单元ID?Admob对我来说很新,我不知道该选择哪个ID。 - Phil

4

如果有人遇到和我一样的问题,我希望能够提供帮助。

我尝试使用新的广告单元ID,但这并没有起作用。最终,问题是因为我试图修复一个被Google Play暂停的应用程序,并且Admob也实际上停止向具有特定包名/捆绑ID的应用程序提供广告。

更改应用程序的包名解决了我的问题。


3

注意广告单元ID字符串。我的错误是在adUnitId的结尾处有一个空格。


1
在您的布局文件(activity_welcome.xml)中,广告视图容器(RelativeLayout)的布局宽度/高度对我来说看起来很奇怪。我认为在您的用例中它是无用的。
从以下内容进行更改:
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true" >

    <com.google.android.gms.ads.AdView
        android:id="@+id/welcomeAdView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="pub-***************" />
</RelativeLayout>

to:

<com.google.android.gms.ads.AdView
    android:id="@+id/welcomeAdView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="pub-***************" />

1

在他们最初发送的电子邮件中,adUintId仅包含正斜杠。从Monetize选项卡获取完整的ID解决了我的问题。 - douggard

0
将以下代码添加到您的清单文件中的application标签内:
<meta-data android:name="com.google.android.gms.version"
     android:value="@integer/google_play_services_version"/>

谢谢你的回复。不幸的是,我的 Manifest.xml 已经包含了这个元数据。我已经将 AndroidManifest.xml 添加到我的问题中了。 - Markus
这非常罕见,我的朋友 :( - edgarmiro

0

您的应用程序可能被 Google AdMob 阻止。如果您收到以下电子邮件:

您好,

此电子邮件是为了提醒您,您的某个应用程序目前不符合我们的 AdMob 程序政策,因此已禁用对您的应用程序的广告投放。

已禁用以下应用程序的广告投放:APPNAME (com.example.pack)

需要采取的措施:检查您帐户中所有其他剩余应用程序是否符合要求。

当前帐户状态:活动中......

因此,您现在需要更改您的应用程序包。在 Eclipse 中,它的包名为“com.example”


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接