2014-05-06 105 views
1

什麼是錯誤?因爲admob interstital廣告不會顯示?由於Admob插頁式廣告不會顯示?

public class MainActivity extends Activity implements AdListener { 
     private InterstitialAd interstitial; 
     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      // Create the interstitial 
      interstitial = new InterstitialAd(this, "ca-app-pub-6xxxxxxxx/xxxxxx"); 
      // 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); 
     } 
    public void onReceiveAd(Ad ad) { 
     // TODO Auto-generated method stub 
     Log.d("ads", "onReceiveAd"); 
     if (ad == interstitial) 
      interstitial.show(); 
    } 

謝謝,我不知道,因爲將不顯示

回答

0

只要按照下面的例子

import com.google.android.gms.ads.*; 

public class BannerExample extends Activity { 

private InterstitialAd interstitial; 

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

// Create the interstitial. 
    interstitial = new InterstitialAd(this); 
    interstitial.setAdUnitId(MY_AD_UNIT_ID); 

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

// Begin loading your interstitial. 
    interstitial.loadAd(adRequest); 
} 
//Invoke displayInterstitial() when you are ready to display an interstitial. 
    public void displayInterstitial() { 

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

我必須插入什麼MY_AD_UNIT_ID? – AnonymousDoor

+0

是的,你必須添加您的插入MY_AD_UNIT_ID像「ca-app-pub-6xxxxxxxx/xxxxxx」 –

+0

謝謝,但是當我插入此代碼的廣告我的應用程序不打開 – AnonymousDoor

0

你應該在創建AdRequest的末尾添加.build()

 // Create ad request 
     AdRequest adRequest = new AdRequest().build(); 
相關問題