如何在应用程序 x 秒后显示插页式广告

How to show Interstitial ads after x seconds on app

我设置了一个在应用程序打开时立即显示的插播广告,但我希望它在一分钟后显示。

这是我的部分代码:

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

    interstitial = new InterstitialAd(MainActivity.this);
    interstitial.setAdUnitId("ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXXXXX");


AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();

    mAdView.loadAd(adRequest);

    interstitial.loadAd(adRequest);

    // Bind to the service
    try {
        bindIntent = new Intent(this, RadioService.class);
        bindService(bindIntent, radioConnection, Context.BIND_AUTO_CREATE);
    } catch (Exception e) {

    }

    telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    if (telephonyManager != null) {
        telephonyManager.listen(phoneStateListener,
                PhoneStateListener.LISTEN_CALL_STATE);
    }

    handler = new Handler();
    initialize();

    // Prepare an Interstitial Ad Listener
    interstitial.setAdListener(new AdListener() {
        public void onAdLoaded() {
            // Call displayInterstitial() function
            displayInterstitial();
        }
    });
}
public void displayInterstitial() {
    // If Ads are loaded, show Interstitial else show nothing.
    if (interstitial.isLoaded()) {
        interstitial.show();
    }
}

欢迎帮助!!

提前致谢!

您可以为此使用处理程序:

Handler handler = new Handler();


     handler.postDelayed(new Runnable(){

                @Override
                public void run() {
      displayInterstitial();
                }
            },60000);

   @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
    }

这里的 60000 是以毫秒为单位的时间

所以如果你需要 20 分钟,那么 60000*20