Admob只显示测试广告,而不显示真实广告



我开发了一款使用AdMob显示广告的应用程序。问题是,在API 24及以上版本中显示的是测试广告,而不是真实广告,而在API 23及以下版本中正常工作。我不知道是哪个问题,但我可以保证:1.我没有实现.addTestDevice2.我使用我的应用程序unitID,而不是测试ID

我附上我的onCreate方法:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_edit_text_note);
//Δημιουργία διαφημίσεων banner
//Φόρτωση διαφημίσεων banner
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

我的布局文件是:

<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:contentDescription="@string/advertisement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-4565************/27********">
</com.google.android.gms.ads.AdView>

我的建筑.gradle:

apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.sebastian_pa.sebastian_v2"
minSdkVersion 16
targetSdkVersion 27
versionCode 4
versionName "1.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.0.1'
implementation 'com.android.support:design:27.0.1'
testImplementation 'junit:junit:4.12'
implementation 'com.google.android.gms:play-services-ads:17.0.0'
}

有人知道为什么会发生这种事吗?

您需要将测试id更改为自己的id。

  1. 在清单文件中
  2. 在中初始化代码
  3. 在您的xml文件中

从你的帖子中,我可以看出你只做了最后一个。

对于步骤1&2,看看这里https://developers.google.com/admob/android/quick-start?hl=en-美国#import_the_mobile_ads_sdk

关于步骤3,请查看此处https://developers.google.com/admob/android/banner?hl=en-美国

最新更新