【发布时间】:2017-08-16 08:27:46
【问题描述】:
我已在我的 Android 应用中集成了 Admob 广告。
测试广告可见。
当我在其他设备上运行应用程序时,在 logcat 中它会显示来自 OnAdLoaded 的日志。
但广告在屏幕上不可见。
可能的原因是什么?您可以提出的任何解决方案将不胜感激
Java 代码
MobileAds.initialize(this, "ca-app-pub-7480926640170381~7951418856");
adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("EDDA7ADAB0640D8A735BAD5C5AD56F06")
.addTestDevice("92C2E8C0BE19A733B5E747993F8DCB69")
.build();
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
Log.i("Ads", "onAdLoaded");
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
Log.i("Ads", "onAdFailedToLoad");
}
@Override
public void onAdOpened() {
// Code to be executed when an ad opens an overlay that
// covers the screen.
Log.i("Ads", "onAdOpened");
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
Log.i("Ads", "onAdLeftApplication");
}
@Override
public void onAdClosed() {
// Code to be executed when when the user is about to return
// to the app after tapping on an ad.
Log.i("Ads", "onAdClosed");
}
});
adView.loadAd(adRequest);
XML CODE:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-7480926640170381/1386010508">
</com.google.android.gms.ads.AdView>
Gradle
compile 'com.google.android.gms:play-services-ads:11.0.0'
【问题讨论】:
-
不看代码很难说,但有几件事您可以尝试 - 1. 其他设备是否已针对测试设备的电子邮件注册? , 2. 您是否真的从 AdMob 获取广告内容?
-
这是我的代码
-
我刚刚编辑了我的问题,请查看@NileshRajani
标签: android android-studio admob