首页 文章

AdMob插页式广告未在Android上展示

提问于
浏览
1

我有一个Android应用程序,我正在尝试添加AdMob插页式广告 . 我这样创造它们

interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(getResources().getString(R.string.ad));
interstitial.loadAd(AdUtils.createRequest());

当适当的时刻,我向他们展示如下:

if(interstitial.isLoaded()) {
    interstitial.show();
}

当我在模拟器上测试这段代码时,一切都很好 . 但是当我在真实设备上运行时,它经常(大约一半的所有节目)只显示带有关闭按钮的黑屏,而根本没有广告图像 . 这个问题有什么解决方案吗?

1 回答

  • 0

    你可以尝试如下 .

    将此声明为变量 .

    private InterstitialAd interstitial;
    

    然后在 onCreate 方法中使用此部分

    interstitial = new InterstitialAd(this, "your id");
    
    // Create ad request
    AdRequest adRequest = new AdRequest();  
    
    // Begin loading your interstitial
    interstitial.loadAd(adRequest);
    
    // Set Ad Listener to use the callbacks below
    interstitial.setAdListener(this);
    

    并最后在你的 onCreate 方法之外设置它,所以基本上设置在你的活动中的代码下面..

    @Override
        public void onReceiveAd(Ad ad) {
            // TODO Auto-generated method stub
            if (ad == interstitial) {
                  interstitial.show();
                }
        }
    

    希望这会帮助你 .

相关问题