广告请求成功,但由于缺少广告资源而没有返回广告 [英] Ad request successful, but no ad returned due to lack of ad inventory
问题描述
我刚接触 AdMob.起初,我试图用不同类型的广告创建一个测试应用程序.我使用真实的 ad_unit_id 和 nexus 4 进行测试.
I new in AdMob. At first I'm trying to create a test app with different types of ad. I use real ad_unit_id and nexus 4 for testing.
我为所有活动使用 1 个布局 xml:
I use 1 layout xml for all activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/empty_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
当我使用横幅广告创建简单的活动时,它工作正常.活动代码:
When i create simple activity with banner ad it's work fine. Activity code:
public class AdBannerActivity extends Activity {
private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ad_empty);
adView = new AdView(this, AdSize.SMART_BANNER, getString(R.string.adUnitId));
adView.setAdListener(this);
LinearLayout layout = (LinearLayout) findViewById(R.id.empty_layout);
layout.addView(adView);
adView.loadAd(new AdRequest());
}
@Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}
当我尝试使用全屏广告创建活动时,出现错误消息:
When i try to create activity with full screen ad, i have error message:
Ad request successful, but no ad returned due to lack of ad inventory.
活动代码:
public class AdInterstitialActivity extends Activity implements AdListener {
private InterstitialAd interstitial;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ad_empty);
interstitial = new InterstitialAd(this, getString(R.string.adUnitId));
interstitial.setAdListener(this);
AdRequest adRequest = new AdRequest();
interstitial.loadAd(adRequest);
}
@Override
public void onReceiveAd(Ad ad) {
if (ad == interstitial) {
interstitial.show();
}
}
@Override
public void onDismissScreen(Ad ad) {
}
@Override
public void onFailedToReceiveAd(Ad ad, ErrorCode error) {
Log.e("AdTest", "Error code: " + error);
}
@Override
public void onLeaveApplication(Ad ad) {
}
@Override
public void onPresentScreen(Ad ad) {
}
}
我做错了什么?如何解决这个问题?
What am I doing wrong? How to solve this problem?
解决方案:为 AdMob 帐户中的插页式广告创建新的 ad_unit_id.
Solution: Create new ad_unit_id for interstitial ads in AdMob account.
推荐答案
如果你有那个错误,那么你的代码是正确的.Admob 没有为您的应用展示任何广告(您所在的国家/地区,您的广告类型是决定因素).
If your have that error, then your code is correct. Admob just doesn't have any ads to display for your app (your country, your type of ads are determinants).
如果您想在测试模式下测试广告的行为,您应该查看此链接:
If you want to test the behavior of your ads in test mode, you should take a look at this link :
https://developers.google.com/mobile-ads-sdk/docs/admob/additional-controls#testmode
如果您刚刚创建了 Admob 帐户,则可能需要一些时间和一些请求来投放第一批广告.我在某处看到人们通过使用自定义横幅大小也有这个错误,所以一定要检查:
EDIT : If you have just created your Admob account, it may take some times and some requests to deliver the first ads. I saw somewhere that people had this error too by using custom size for banner, so be sure to check :
https://developers.google.com/mobile-ads-sdk/docs/admob/intermediate#play
这篇关于广告请求成功,但由于缺少广告资源而没有返回广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!