2014-03-01 64 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

相關問題