获得广告响应。 ErrorCode:0

时间:2015-05-15 13:17:07

标签: java android admob

这是我第一次设置和编写Android应用程序,也是我第一次设置广告,我一直在谷歌搜索和测试将近2天,但我仍然无法让广告出现,它仍然给我错误“获得广告响应时出现问题.ResuCode:0”。我已按照here的指南进行操作。下面是我的下方,请帮助:(

MainActivity.java

package com.example.lechoonh.admob;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

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


public class MainActivity extends ActionBarActivity {

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

    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
    .addTestDevice("DAE102189E22517B3A0C8A79337B74A2")
    .build();
    mAdView.loadAd(adRequest);


}

的build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.example.lechoonh.admob"
    minSdkVersion 9
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.0.0'
}

的AndroidManifest.xml

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

    <application
    android:allowBackup="true"
    android:icon="@mipmap/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=".MainActivity"
        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.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />
        />

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

的strings.xml

<resources>
    <string name="app_name">Admob 2</string>

    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string name="banner_ad_unit_id">ca-app-pub-xxxxxxxxxxxxx/xxxxx</string>
</resources>

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 xmlns:ads="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="match_parent"     android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">



<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true">
</com.google.android.gms.ads.AdView>

Picture

2 个答案:

答案 0 :(得分:2)

好的,事实证明我应该从

更新依赖项

com.google.android.gms:播放服务:7.0.0

到com.google.android.gms:play-services:7.3.0

现在广告正确显示

答案 1 :(得分:0)

在我的情况下,我开始在新设备上开发并忘记更新测试设备ID。

AdView adMapView = (AdView)findViewById(R.id.adMapView);
AdRequest adMapRequest = new AdRequest.Builder().addTestDevice("THIS IS WHERE YOU DEVICE ID GOES AND INCLUDE THE Parenthesis").build();

在Logcat中查找当前设备ID的这一行:

10-18 10:48:40.123 7731-7731/? I/Ads: Use AdRequest.Builder.addTestDevice("xxxxxxxxxxxxxxxxxxxxxxxxxx") to get test ads on this device.

为我修好了。