2014-03-01 67 views
1

我有一个Android应用程序,我正在尝试向其中添加AdMob插页式广告。我创建它们这样AdMob插页式广告未在Android上显示

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

而当那一刻是合适的,我告诉他们这样的:

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

当我在模拟器上测试该代码,一切都很好。但是当我在真实设备上运行它时,它经常(大约一半的节目)仅显示黑屏,并且关闭按钮并且根本没有广告图像。有没有解决这个问题的方法?

+0

请尝试下面的代码,让我知道它是否工作与否。 – InnocentKiller

回答

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(); 
      } 
    } 

希望这会外会帮助你。

+0

谢谢,但我使用Google Play版本的Mobile Ads SDK,与您的版本略有不同 – windsor

相关问题