作为计时哼声插页式广告?

时间:2016-06-21 16:09:23

标签: android timer admob interstitial

示例:我想要的当您打开应用程序时,广告会在5秒内出现,如果不同,将取消展览并且应用程序将继续执行主要活动段落。我使用的代码是:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    interstitialAd = new InterstitialAd(Main.this);
    interstitialAd.setAdUnitId(getString(R.string.adMobInter));
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice(getString(R.string.adMob_test))
            .build();
    interstitialAd.loadAd(adRequest);

    interstitialAd.setAdListener(new AdListener() {


        @Override
        public void onAdLoaded() {

               displayInterstitial();

        }

        @Override
        public void onAdFailedToLoad(int errorCode) {

            onMain();


        }

        @Override
        public void onAdClosed() {

            onMain();

        }
    });

}

public void displayInterstitial() {

    if (interstitialAd.isLoaded())  {
        interstitialAd.show();

    }
}

public void onMain() {

    setContentView(R.layout.main);
}

0 个答案:

没有答案