2017-02-23 45 views
1

我想admob沒有按添加插頁廣告的任何按鈕,但
它不會出現你能幫助我試着下面的代碼:添加間質性AdMob廣告沒有按下按鈕

... 
public class MainActivity extends ActionBarActivity { 

    InterstitialAd mInterstitialAd; 
    Button mNewGameButton; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 


     mInterstitialAd = new InterstitialAd(this); 
     mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712"); 

     mInterstitialAd.setAdListener(new AdListener() { 
      @Override 
      public void onAdClosed() { 
       requestNewInterstitial(); 
       beginPlayingGame(); 
      } 
     }); 

     requestNewInterstitial(); 

     mNewGameButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       if (mInterstitialAd.isLoaded()) { 
        mInterstitialAd.show(); 
       } else { 
        beginPlayingGame(); 
       } 
      } 
     }); 

     beginPlayingGame(); 
    } 

    private void requestNewInterstitial() { 
     AdRequest adRequest = new AdRequest.Builder() 
       .addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID") 
       .build(); 

     mInterstitialAd.loadAd(adRequest); 
    } 

    private void beginPlayingGame() { 
     // Play for a while, then display the New Game Button 
    } 
} 
... 

回答

0

真正的答案在這裏,我發現它

interstitialAd.setAdListener(new AdListener() { 
public void onAdLoaded() { 
    Handler handler = new Handler(); 
    handler.postDelayed(new Runnable() { 
     public void run() { 
      MainActivity.this.interstitialAd.show(); 
     } 
    }, 5000); 
}} ); 
2

在加載插件您必須添加一個用於測試的設備ID。而烏爾運行該代碼中看到烏爾logcat中看到的設備ID ..複製和設備ID粘貼到附加的測試設備和重新運行U將開始看到添加

公共類MainActivity擴展ActionBarActivity {

InterstitialAd mInterstitialAd; 
Button mNewGameButton; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 


    mInterstitialAd = new InterstitialAd(this); 
    mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712"); 

在AdRequest adRequest = new AdRequest.Builder() .addTestDevice(「SEE_YOUR_LOGCAT_TO_GET_YOUR_DEViCE_ID」)。build();

mInterstitialAd.loadAd(adRequest); 
    mInterstitialAd.setAdListener(new AdListener() { 
     @Override 
     public void onAdClosed() { 
      requestNewInterstitial(); 
      beginPlayingGame(); 
     } 
    }); 

    requestNewInterstitial(); 

      if (mInterstitialAd.isLoaded()) { 
       mInterstitialAd.show(); 
      } else { 
       beginPlayingGame(); 
      } 


    beginPlayingGame(); 
}