2014-10-29 85 views
0

Iam嘗試使用Admob顯示廣告,但Iam沒有收到任何對onAdloaded.Can的呼叫...有人幫助... Iam顯示第一個ad.Iam設置,然後Iam嘗試加載它.. 。在onAdLoaded上沒有獲得回調

@Override 
protected void onCreate(Bundle arg0) { 
    super.onCreate(arg0);  
    CalligraphyConfig.initDefault(getString(R.string.font_alegreya_sans_regular)); 
    setInterstitialAd(); 
    setContentView(R.layout.splashscreen_activity); 
} 

private void setInterstitialAd() { 
    mInterstitial = new InterstitialAd(this); 
    mInterstitial.setAdUnitId(INTERSTITIAL_AD_ID); 

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

    // Begin loading your interstitial. 
    mInterstitial.loadAd(adRequest); 
    mInterstitial.setAdListener(new AdListener() { 
     @Override 
     public void onAdLoaded() { 
      displayInterstitial(); 
     } 

     @Override 
     public void onAdFailedToLoad(int errorCode) { 

     } 

}); }

private void initAdView() { 
    AdView mAdView = (AdView) findViewById(R.id.ad_container_layout); 
    AdRequest adRequest = new AdRequest.Builder().build(); 
    mAdView.loadAd(adRequest); 
} 
+0

你確定沒有調用onAdLoaded()嗎?你可以檢查logcat輸出嗎? Admob在完成加載廣告後將其記錄下來。您也可以在onAdLoaded中添加自己的日誌以確保。顯然你還需要一個互聯網連接,並具有互聯網接入的Android權限。另外,這個displayInterstitial()方法在哪裏? – donfuxx 2014-10-29 13:09:21

回答

0

您should'nt有displayInterstitial()內onAdLoaded()。這導致廣告未被展示的結果。既可以在某個級別後顯示廣告,也可以在五級後顯示廣告,其中一個顯示插頁式廣告,它會進入暫停菜單。你保持它從之前加載並顯示在第五級。或者使用計時器(包括displayInterstitial())包含一段時間後,您可以在暫停菜單中使用它。

+0

不是。如果您確實想要,那麼只要加載它即可顯示插頁式廣告。對於用戶體驗來說,這很可能不是最好的解決方案,但從技術上來說顯然是可能的。 – donfuxx 2014-10-29 13:11:52

+0

它不適合他,這就是他爲什麼要求在計算器上。他說這種方式廣告不顯示。我之前嘗試過,它不起作用。它只能按照官方google教程中描述的方式工作,它在調用displayInterstitial()之前並不要求onAdLoaded的任何條件。因爲在displayInterstitial()裏面,它已經檢查if(interstitial.isLoaded())。所以請在太明顯和技術性之前驗證一下。 – Kunalxigxag 2014-10-30 13:58:57

+0

並btw @suraj你從這裏正確得到了displayInterstitial()類 - https://developers.google.com/mobile-ads-sdk/docs/admob/android/interstitial – Kunalxigxag 2014-10-30 13:59:18

0

Suraj,在這兩種回調方法中添加一些日誌。其中一人將被召喚。 我懷疑廣告請求失敗,因此onFailedToLoad()將會被調用。

另外不要請致電displayInterstitial()onAdLoaded()。這會導致非常差的用戶體驗,並可能會禁止您的Admob帳戶。

相關問題