Admob 插页式广告不会显示 [英] Admob interstitial ad won't display

查看:33
本文介绍了Admob 插页式广告不会显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经在我未来的应用中展示 AdMob 横幅,我想尝试一下插页式广告.

我检查了 AdMob SDK 的实施情况,并复制了他们的示例源代码,因为这正是我想要的(即活动启动时显示的插页式广告).

我在模拟器和我的 Galaxy 上尝试过,没有显示任何广告.

这里是源代码:

公共类 Asscreed 扩展 Activity {私人插页式广告插页式广告;@覆盖protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_asscreed);//创建插页式广告.插页式 = 新的插页式广告(此);interstitial.setAdUnitId("ca-app-pub-6046034785851961/xxxxxx");//创建广告请求.AdRequest adRequest = new AdRequest.Builder().build();//开始加载您的插页式广告.interstitial.loadAd(adRequest);}//当您准备好显示插页式广告时调用 displayInterstitial().公共无效显示插页式(){if (interstitial.isLoaded()) {interstitial.show();}}}

导入正常,当然也导入了 Google Play 服务库.

我使用以下示例:AdMob Android 指南 - 插页式广告.

谁能告诉我我的代码有什么问题?

解决方案

您应该等待广告加载完毕.只有这样,您才能调用 displayInterstial() 方法来展示广告.

您可以注册一个监听器,它会在加载完成时通知您.

<上一页>interstitial.setAdListener(new AdListener(){公共无效 onAdLoaded(){显示插页式();}});

I used to display AdMob banner on my future apps, and I'd like to give a try to the interstitial ads.

I checked the AdMob SDK for implementation, and I copied their example source because it was exactly what I want (i.e. the interstitial shown when the activity launch).

I tried it on emulator and on my Galaxy, no ad has been displayed.

Here is the source code:

public class Asscreed extends Activity {
    private InterstitialAd interstitial;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_asscreed);

        // Create the interstitial.
        interstitial = new InterstitialAd(this);
        interstitial.setAdUnitId("ca-app-pub-6046034785851961/xxxxxx");

        // Create ad request.
        AdRequest adRequest = new AdRequest.Builder().build();

        // Begin loading your interstitial.
        interstitial.loadAd(adRequest);
    }

    // Invoke displayInterstitial() when you are ready to display an interstitial.
    public void displayInterstitial() {
        if (interstitial.isLoaded()) {
            interstitial.show();
        }
    }
}

The imports are OK and the Google Play Services library is of course imported.

I use this example: AdMob Android Guides - Interstitial Ad.

Could someone tell me what's wrong in my code?

解决方案

You should wait for the ad to be loaded. Only then, you can call displayInterstial() method, which would show the ad.

You can register for a listener, that will let you know when the loading is done.

interstitial.setAdListener(new AdListener(){
          public void onAdLoaded(){
               displayInterstitial();
          }
});

这篇关于Admob 插页式广告不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆