广告不显示。我已将我的设备配置为测试单元。
MobileAds.initialize(getActivity(), new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
//setup test device
MobileAds.setRequestConfiguration(
new RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("A222ECB948AFB6D392596135E7D33D35"))
.build());
mAdView = root.findViewById(R.id.adView);
final AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAdView.setAdListener( new AdListener(){
@Override
public void onAdLoaded() {
Log.i("nonsinglefragment","ad loaded");
super.onAdLoaded();
}
@Override
public void onAdFailedToLoad(int i) {
Log.i("nonsinglefragment","ad load failed "+i);
super.onAdFailedToLoad(i);
}
});
Xml代码
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:adSize="BANNER"
app:adUnitId="@string/ad_id1"/>
这是logcat
I/Ads: Updating ad debug logging enablement.
I/Ads: This request is sent from a test device.
W/Ads: Not retrying to fetch app settings
I/Ads: This request is sent from a test device.
W/Ads: Not retrying to fetch app settings
W/Ads: Update ad debug logging enablement as false
I/Ads: Ad failed to load : 0
I/Ads: Ad failed to load : 0
使用google的样本测试id,一切都很正常。当我实施我的单元ID时,问题开始了。
请确保你的Admob帐户是活跃的,如果它是活跃的,那么你可以等待一些小时,有时广告需要时间出现。
这是谷歌文档中说的。
"这可能是你最近才创建了一个新的广告单位ID和请求现场广告。它可能需要几个小时的广告开始得到服务,如果是这种情况。如果你收到的是测试广告,那么你的执行情况是好的。只是等待几个小时,看看你是否能够收到实时广告。如果不能,可以把你的广告单元ID发给我们,让我们研究一下。"