this is my first time setting up and writing an android app, and also my first time setting up an ad, I've been googling and testing for almost 2 days but I still can't seem to make the ad appear and it still gives me the error "There was a problem getting an ad response. ErrorCode: 0". I've followed the guide at here Below are my below, please help :(
这是我第一次设置和编写一个android应用,也是我第一次设置一个广告,我用google搜索和测试已经几乎两天但我仍然不能使广告出现,它仍然给了我错误的“有问题的广告的反应。错误代码:0”。下面是我下面的指南,请帮忙:
MainActivity.java
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
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
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
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
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>
2 个解决方案
#1
2
Ok, it turns out that I should update the dependencies from
好的,我应该更新依赖项。
com.google.android.gms:play-services:7.0.0
com.google.android.gms:游戏服务:7.0.0
to com.google.android.gms:play-services:7.3.0
com.google.android.gms:游戏服务:7.3.0
now the ads appeared correctly
现在广告出现了。
#2
0
In my case I had started to develop on a new device and forgot to update the test device id.
在我的例子中,我已经开始在一个新设备上开发,并且忘记了更新测试设备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();
AND look for this line in your Logcat for your current device ID:
在Logcat中查找当前设备ID的这一行:
10-18 10:48:40.123 7731-7731/? I/Ads: Use AdRequest.Builder.addTestDevice("xxxxxxxxxxxxxxxxxxxxxxxxxx") to get test ads on this device.
Fixed it for me.
给我固定它。
#1
2
Ok, it turns out that I should update the dependencies from
好的,我应该更新依赖项。
com.google.android.gms:play-services:7.0.0
com.google.android.gms:游戏服务:7.0.0
to com.google.android.gms:play-services:7.3.0
com.google.android.gms:游戏服务:7.3.0
now the ads appeared correctly
现在广告出现了。
#2
0
In my case I had started to develop on a new device and forgot to update the test device id.
在我的例子中,我已经开始在一个新设备上开发,并且忘记了更新测试设备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();
AND look for this line in your Logcat for your current device ID:
在Logcat中查找当前设备ID的这一行:
10-18 10:48:40.123 7731-7731/? I/Ads: Use AdRequest.Builder.addTestDevice("xxxxxxxxxxxxxxxxxxxxxxxxxx") to get test ads on this device.
Fixed it for me.
给我固定它。