2012-11-28 64 views
1

我的應用程序已使用以下InterstitialAd,下面是從谷歌示例中獲得的標準編碼。不過,我想問問爲什麼沒有廣告顯示? (應用程序正常顯示吐司:在ReceiveAd上)android interstitialad不顯示

我的main_first_page佈局在底部也有一個廣告條。這會影響InterstitialAd嗎?

謝謝!

public class StartUp extends Activity implements AdListener { 

    private InterstitialAd interstitialAd; 
    AdView adView; 
    private static final String LOG_TAG = "IQ!"; 

     public static final String MY_PUBLISHER_ID = "abc"; 

     @Override 
     public void onCreate(Bundle savedInstanceState) 
     { 
      super.onCreate(savedInstanceState); // call the superclass's method 
      setContentView(R.layout.main_first_page); // inflate the GUI 


      Button ButtonNum= (Button) findViewById(R.id.buttonB); 
      Button ButtonHeart= (Button) findViewById(R.id.buttonC); 
      Button ButtonMath= (Button) findViewById(R.id.buttonD);    

      interstitialAd = new InterstitialAd(this, MY_PUBLISHER_ID); // Create an ad. 
       interstitialAd.setAdListener(this); // Set the AdListener. 
       AdRequest adRequest = new AdRequest(); 
       adRequest.addTestDevice(AdRequest.TEST_EMULATOR); 
       interstitialAd.loadAd(adRequest);  

       if (interstitialAd.isReady()) {interstitialAd.show();} 
       else {Log.d(LOG_TAG, "Interstitial ad was not ready to be shown.");}    
     } 
/** Called when an ad is clicked and about to return to the application. */ 
      @Override 
      public void onDismissScreen(Ad ad) { 
      Log.d(LOG_TAG, "onDismissScreen"); 
      Toast.makeText(this, "onDismissScreen", Toast.LENGTH_SHORT).show(); 
      } 

/** Called when an ad was not received. */ 
      @Override 
      public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode error) { 
      String message = "onFailedToReceiveAd (" + error + ")"; 
      Log.d(LOG_TAG, message); 
      Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); 
      } 

/** Called when an ad is clicked and going to start a new Activity that will 
      * leave the application (e.g. breaking out to the Browser or Maps 
      * application). 
      */ 
      @Override 
      public void onLeaveApplication(Ad ad) { 
      Log.d(LOG_TAG, "onLeaveApplication"); 
      Toast.makeText(this, "onLeaveApplication", Toast.LENGTH_SHORT).show(); 
      } 

/* Called when an Activity is created in front of the app (e.g. an 
      * interstitial is shown, or an ad is clicked and launches a new Activity). 
      */   
     @Override 
     public void onPresentScreen(Ad arg0) { 
      // TODO Auto-generated method stub   
     } 

/** Called when an ad is received. */ 
     @Override 
      public void onReceiveAd(Ad ad) { 
      Log.d(LOG_TAG, "onReceiveAd"); 
      Toast.makeText(this, "onReceiveAd", Toast.LENGTH_SHORT).show(); 
     } 

回答

6

插頁式廣告需要時間加載。你正在檢查加載它後是否準備好,所以它肯定還沒有準備好。檢查你的logcat輸出,你可能會看到你記錄的"Interstitial ad was not ready to be shown."消息。

直到調用onReceiveAd()回調,插頁式廣告纔會準備就緒。您可以安全地將interstitialAd.show()放置在onReceiveAd()回撥中,插頁式廣告將立即顯示。

另一個用例可能是您希望在稍後顯示插頁式廣告,例如遊戲關卡的結尾。在這種情況下,您需要在關卡開始時預加載插頁式廣告,然後查看關卡末尾的isReady標誌,以查看插頁式廣告是否已準備就緒。

+0

非常感謝您的幫助!我還沒有想過在onReceiveAd()回調中放置interstitialAd.show(),這樣插頁式廣告就會立即顯示!有用! – pearmak

+1

如果您預先加載了intersticial(這是一種減少感知延遲加載的好方法),但請注意它會影響您的點擊率(點擊率)。點擊率計算爲Number_Of_Clicks/Number_Of_Requests。如果您預加載它但不顯示它(如果播放器沒有達到關卡的末端),則用戶無法點擊,儘管它已被請求。 Google和廣告客戶使用CTR來優化他們發送到應用的廣告系列。 因此,如果您確定(或幾乎確定)您最終將顯示它,我建議預先加載它。我就是做這個的。 – Erwan

+0

我對此有一個問題:http://stackoverflow.com/questions/36389729/ads-are-loading-but-not-showing/36389781?noredirect=1#comment60396446_36389781 –