[英]AdMob - Ad not displayed - Error 2
I am building an android application that has two versions.One with Ad. 我正在构建一个具有两个版本的android应用程序。一个带有广告。 and one with out Ad. 还有一个没有广告 . 。 I've successfully integrated the AdMob
in the application. 我已成功将AdMob
集成到应用程序中。 but the Ads are not getting displayed on the screen. 但是广告没有显示在屏幕上。
Here's my 这是我的
build.gradle 的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors{
free{
applicationId "com.myapp"
buildConfigField "boolean","IS_PAID_VERSION", "false"
}
paid{
applicationId "com.myapp.paid"
buildConfigField "boolean","IS_PAID_VERSION", "true"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services-ads:8.4.0'
}
activity_main.xml activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context="com.myapp.activities.AdTestActivity">
<com.google.android.gms.ads.AdView
android:id="@+id/ad_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/ad_unit_id" />
</RelativeLayout>
AdTestActivity.java AdTestActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.myapp.R;
public class AdTestActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ad_test);
final AdView adView = (AdView) findViewById(R.id.ad_view);
final AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("A144A6A159A94CC77CE70EC1A874B93A") //My test device 1
.addTestDevice("8477FA9B6C105C84897FC2717E19A548") //My test device 2
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
adView.loadAd(adRequest);
}
}
The ad is no getting displayed on the screen, and the logcat
says... 广告没有显示在屏幕上, logcat
显示...
I/Ads: Starting ad request.
02-12 00:24:41.381 15472-15493/com.myapp W/Ads: There was a problem getting an ad response. ErrorCode: 2
02-12 00:24:41.382 15472-15472/com.myapp I/Ads: Scheduling ad refresh 60000 milliseconds from now.
02-12 00:24:41.382 15472-15472/com.myapp W/Ads: Failed to load ad: 2
PS: I've a good internet connection and valid AdUnitId
. PS:我的网络连接良好且有效的AdUnitId
。 I don't have any kind of AdBlock
applications in my device. 我的设备中没有任何类型的AdBlock
应用程序。 I've also read all SO threads about this problem, but none of them worked for me. 我还阅读了有关此问题的所有SO线程,但没有一个对我有用。
What am i doing wrong here ? 我在这里做错了什么? :( :(
I had the same issue and I fixed it by updating Google Play Services to the latest version on my mobile. 我遇到了同样的问题,并通过将Google Play服务更新到手机上的最新版本来解决。 So maybe try updating it from Play Store. 因此,也许尝试从Play商店对其进行更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.